home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- Module name: PHIGS menus utility
-
- Author: Karen Wyrwas
-
- Function: This module contains the PHIGS utility routines
- for menus and high level input tools. They are all built on top of PHIGS.
-
- External function list: ptk_createboxmenu, ptk_createboxmenuitem,
- ptk_createusermenu, ptk_createusermenuitem, ptk_drawmenu, ptk_erasemenu,
- ptk_scanmenus, ptk_delmenu, ptk_delmenuitem, ptk_createrotator.
-
- Internal function list: getmenu, getmenuid, ptk_findnextpickid,
- find_insertion_pt, find_item, shift_items, delete_item, point_in_menu,
- find_string, string_in_menu, pick_in_menu, disposemenus, get_tlboxcorner,
- insert_box_item, insert_user_item.
-
- Hashtables used: "structureid", "name", "label".
-
- Modification history: (Version), (Date), (Name), (Description).
-
- 1.0, 9th March 1988, Karen Wyrwas, First version.
-
- 1.1, 31st October 1988, Karen Wyrwas, Add rotator routines.
-
- 1.2, 1st November 1988, Karen Wyrwas, Port to VAX PHIGS.
-
- 2.0, 25th April 1991, Gareth Williams, Translated to C.
-
- 2.1, 16th May 1991, Gareth Williams, Functions getmenu, getmenuid,
- disposemenus, ptk_inqpickmenus added.
-
- 2.2, 23rd May 1991, Gareth Williams, Built rotators on top of user menus.
-
- 3.0, June 1992, Gareth Williams, Converted to ISO PHIGS C.
-
- ---------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- /*--------------------------------------------------------------------------*/
-
- #define PTKCPOSY 1
- #define PTKCNEGY 2
- #define PTKCPOSX 4
- #define PTKCNEGX 3
- #define PTKCPOSZ 5
- #define PTKCNEGZ 6
-
- /*--------------------------------------------------------------------------*/
-
- typedef struct ptksmenu
- {
- Pint menuid;
- Pint menustid;
- Pint wsid;
- Pint highlight;
- Pint font;
- Pint menuname;
- Pint_list posted;
-
- ptkemenutype menutype;
- Ptext_path menupath;
- Ppoint menuposition;
- Pfloat charheight;
- Pint maxitem;
- char longstr[255];
- Pint intcolour, edgecolour, tlcolour, brcolour, textcolour;
- Pint htintcolour, htedgecolour, httlcolour, htbrcolour, httextcolour;
- Ppoint framesize;
- Ppoint boxsize;
-
- /* rotator */
- Ppoint bannercentre, bannerbox;
- Pint arrowcolour, arrowedgecolour, bannercolour;
-
- struct ptksmenu *next;
- } ptksmenu;
-
- typedef struct
- {
- ptkboolean postedmenus;
- ptksmenu *frontptr;
- ptksmenu *backptr;
- } ptkswsmenu;
-
- /*--------------------------------------------------------------------------*/
-
- static ptksmenu *menuptr = NULL;
- static ptksmenu *firstmenu = NULL;
- static ptksmenu *lastmenu = NULL;
-
- static Pint numwsids = 0;
- static Pint wsids[10];
- static ptkswsmenu wsmenus[10];
- static Pint menucount = 0;
-
- /*--------------------------------------------------------------------------*/
- /* utility routines */
- /*--------------------------------------------------------------------------*/
-
- static void setmenu(C(Pint) menuid)
- PreANSI(Pint menuid)
- {
- ptksmenu *ptr;
-
- if (firstmenu == NULL)
- {
- menuptr = NULL;
- return;
- }
- ptr = firstmenu;
- while (ptr->menuid != menuid)
- {
- ptr = ptr->next;
- if (ptr == NULL)
- {
- menuptr = NULL;
- return;
- }
- }
- menuptr = ptr;
- } /* setmenu */
-
- /*-------------------------------------------------------------------------*/
-
- static void findwsid(C(Pint) wsid, C(Pint *) ind)
- PreANSI(Pint wsid)
- PreANSI(Pint *ind)
- {
- Pint i;
-
- *ind = -1;
- for (i = 0; i < numwsids; i++)
- if (wsids[i] == wsid)
- *ind = i;
- } /* findwsid */
-
- /*--------------------------------------------------------------------------*/
-
- static void checkws(C(Pint) wsid)
- PreANSI(Pint wsid)
- {
- Pint ind;
-
- findwsid(wsid, &ind);
- if (ind == -1)
- {
- wsids[numwsids] = wsid;
- wsmenus[numwsids].postedmenus = FALSE;
- wsmenus[numwsids].frontptr = NULL;
- wsmenus[numwsids].backptr = NULL;
- numwsids++;
- }
- } /* checkws */
-
- /*--------------------------------------------------------------------------*/
-
- static ptkboolean getmenuid(C(Pint) menustid, C(Pint *) menuid)
- PreANSI(Pint menustid)
- PreANSI(Pint *menuid)
- {
- ptksmenu *ptr;
-
- ptr = firstmenu;
- while (ptr->menustid != menustid)
- {
- ptr = ptr->next;
- if (ptr == NULL)
- return FALSE;
- }
- *menuid = ptr->menuid;
- return TRUE;
- } /* getmenuid */
-
- /*-------------------------------------------------------------------------*/
-
- static ptkboolean ismenu(C(Pint) menustid, C(ptksmenu **) mptr)
- PreANSI(Pint menustid)
- PreANSI(ptksmenu **mptr)
- {
- ptksmenu *ptr;
- ptkboolean found;
-
- ptr = firstmenu;
- found = FALSE;
- while ((ptr != NULL) && (!found))
- {
- if (ptr->menustid == menustid)
- {
- *mptr = ptr;
- found = TRUE;
- }
- else
- ptr = ptr->next;
- }
- return found;
- } /* ismenu */
-
- /*--------------------------------------------------------------------------*/
-
- static void findfront(C(Pint) wsid, C(ptkswsmenu *) wsfront)
- PreANSI(Pint wsid)
- PreANSI(ptkswsmenu *wsfront)
- {
- Pposted_struct_list structlist;
- Pint numstructs, error, i;
- Pfloat priority;
- ptkboolean found;
- ptksmenu *mptr;
-
- priority = 0.0;
- found = FALSE;
- i = 0;
- pinq_posted_structs(wsid, 0, 0, &error, &structlist, &numstructs);
- structlist.postings = (Pposted_struct *)calloc(numstructs,
- sizeof(Pposted_struct));
- pinq_posted_structs(wsid, numstructs, 0, &error, &structlist, &numstructs);
- for (i = 0; i < numstructs; i++)
- {
- /* find highest priority menu structure */
- if (ismenu(structlist.postings[i].id, &mptr))
- if (structlist.postings[i].disp_pri > priority)
- {
- priority = structlist.postings[i].disp_pri;
- wsfront->frontptr = mptr;
- found = TRUE;
- }
- }
- if (!found)
- wsfront->postedmenus = FALSE;
- } /* findfront */
-
- /*--------------------------------------------------------------------------*/
-
- static void findback(C(Pint) wsid, C(ptkswsmenu *) wsback)
- PreANSI(Pint wsid)
- PreANSI(ptkswsmenu *wsback)
- {
- Pposted_struct_list structlist;
- Pint numstructs, error, i;
- Pfloat priority;
- ptkboolean found;
- ptksmenu *mptr;
-
- priority = 1.0;
- found = FALSE;
- i = 0;
- pinq_posted_structs(wsid, 0, 0, &error, &structlist, &numstructs);
- structlist.postings = (Pposted_struct *)calloc(numstructs,
- sizeof(Pposted_struct));
- pinq_posted_structs(wsid, numstructs, 0, &error, &structlist, &numstructs);
- for (i = 0; i < numstructs; i++)
- {
- /* find lowest priority menu structure */
- if (ismenu(structlist.postings[i].id, &mptr))
- if (structlist.postings[i].disp_pri < priority)
- {
- priority = structlist.postings[i].disp_pri;
- wsback->backptr = mptr;
- found = TRUE;
- }
- }
- if (!found)
- wsback->postedmenus = FALSE;
- } /* findback */
-
- /*--------------------------------------------------------------------------*/
-
- static void find_insertion_pt(C(Pint) menustid, C(Pint) itemno,
- C(Pint *) eltptr, C(Pint *) itemfound)
- PreANSI(Pint menustid)
- PreANSI(Pint itemno)
- PreANSI(Pint *eltptr)
- PreANSI(Pint *itemfound)
- /*
- ** \parambegin
- ** \param{}{menustid}{menu structure id}{IN}
- ** \param{}{itemno}{number of menu item}{IN}
- ** \param{}{eltptr}{element pointer of pick id}{IN}
- ** \param{}{itemfound}{pick id value}{IN}
- ** \paramend
- ** \blurb{Search struct for `set pick id' structure elements until
- ** either get to end of structure or a pick id >= `itemno' is found,
- ** in which case the element number of the corresponding structure element
- ** is returned (this is the point at which "itemno" will be inserted).
- ** `itemfound' indicates whether or not the pick id found was `itemno'.
- ** Returns TRUE if pick id found, otherwise FALSE.}
- */
- {
- Pint pickid;
- ptkboolean finished;
-
- finished = FALSE;
- *itemfound = -1;
- *eltptr = 2;
- do
- {
- if (ptk_findnextpickid(menustid, PDIR_FORWARD, eltptr, &pickid))
- {
- if (pickid >= itemno)
- {
- *itemfound = pickid;
- finished = TRUE;
- }
- else
- (*eltptr)++;
- }
- else
- {
- *eltptr = ptk_elemcount(menustid) - 1;
- finished = TRUE;
- }
- } while (!finished);
- } /* find_insertion_pt */
-
- /*--------------------------------------------------------------------------*/
-
- static void finditemrange(C(Pint) menustid, C(Pint) itemno,
- C(Pint *) elem1, C(Pint *) elem2)
- PreANSI(Pint menustid)
- PreANSI(Pint itemno)
- PreANSI(Pint *elem1)
- PreANSI(Pint *elem2)
- /*
- ** \parambegin
- ** \param{}{menustid}{menu structure id}{IN}
- ** \param{}{itemno}{number of menu item}{IN}
- ** \param{}{eltptr}{element pointer of pick id}{IN}
- ** \param{}{itemfound}{pick id value}{IN}
- ** \paramend
- ** \blurb{Search struct for `set pick id' structure elements until
- ** either get to end of structure or a pick id >= `itemno' is found,
- ** in which case the element number of the corresponding structure element
- ** is returned (this is the point at which "itemno" will be inserted).
- ** `itemfound' indicates whether or not the pick id found was `itemno'.
- ** Returns TRUE if pick id found, otherwise FALSE.}
- */
- {
- Pint pickid;
- ptkboolean finished;
-
- finished = FALSE;
- *elem1 = 1;
- do
- {
- if (ptk_findnextpickid(menustid, PDIR_FORWARD, elem1, &pickid))
- {
- if (pickid == itemno)
- {
- *elem2 = *elem1 + 1;
- if (ptk_findnextpickid(menustid, PDIR_FORWARD, elem2, &pickid))
- {
- (*elem2)--;
- finished = TRUE;
- }
- else
- {
- *elem2 = ptk_elemcount(menustid) - 2;
- finished = TRUE;
- }
- }
- else
- (*elem1)++;
- }
- else
- {
- *elem1 = *elem2 = -1;
- finished = TRUE;
- }
- } while (!finished);
- } /* finditemrange */
-
- /*--------------------------------------------------------------------------*/
-
- static ptkboolean find_item(C(Pint) menustid, C(Pint) itemno, C(Pint *) eltptr)
- PreANSI(Pint menustid)
- PreANSI(Pint itemno)
- PreANSI(Pint *eltptr)
- /*
- ** \parambegin
- ** \param{}{menustid}{menu structure id}{IN}
- ** \param{}{itemno}{menu item number}{IN}
- ** \param{}{eltptr}{element pointer of pick id}{IN}
- ** \paramend
- ** \blurb{Look for item in menu.
- ** Returns TRUE if item found, otherwise FALSE.}
- */
- {
- Pint pickid;
- ptkboolean found;
-
- *eltptr = 2;
- found = FALSE;
- do
- {
- if (ptk_findnextpickid(menustid, PDIR_FORWARD, eltptr, &pickid))
- {
- if (pickid == itemno)
- found = TRUE;
- else
- (*eltptr)++;
- }
- else
- *eltptr = -1;
- } while ((!found) && (*eltptr != -1));
- return found;
- } /* find_item */
-
- /*--------------------------------------------------------------------------*/
-
- static Ppoint3 get_tlboxcorner(C(Pint) itemno)
- PreANSI(Pint itemno)
- /*
- ** \parambegin
- ** \param{}{itemno}{menu item number}{IN}
- ** \paramend
- ** \blurb{Get top left corner of box menu item.
- ** Returns top left corner of menu item.}
- */
- {
- Ppoint3 temp;
-
- temp = ptk_point3(0.0, 0.0, 0.0);
- switch (menuptr->menupath)
- {
-
- case PPATH_RIGHT:
- temp.x = (Pfloat)(itemno - 1) * menuptr->boxsize.x;
- break;
-
- case PPATH_LEFT:
- temp.x = (Pfloat)(1 - itemno) * menuptr->boxsize.x;
- break;
-
- case PPATH_UP:
- temp.y = (Pfloat)(itemno - 1) * menuptr->boxsize.y;
- break;
-
- case PPATH_DOWN:
- temp.y = (Pfloat)(1 - itemno) * menuptr->boxsize.y;
- break;
- }
- return temp;
- } /* get_tlboxcorner */
-
- /*--------------------------------------------------------------------------*/
-
- static void shift_items(C(Pint) eltno, C(Pint) shiftby)
- PreANSI(Pint eltno)
- PreANSI(Pint shiftby)
- /*
- ** \parambegin
- ** \param{}{menustid}{menu structure id}{IN}
- ** \param{}{eltno}{element pointer of first pickid in menu}{IN}
- ** \param{}{menuinfo}{menu description data}{IN}
- ** \param{}{shiftby}{amount to shift boxes}{IN}
- ** \paramend
- ** \blurb{If menu is a `box' menu, shift subsequent items by size of
- ** box and increment item number.}
- */
- {
- Pmatrix3 shiftmat;
- Pint pickid;
- ptkboolean end_of_struct;
- Ppoint3 shift;
-
- /* replace subsequent "set pick id" elts with pick id = pick id + shiftby */
- end_of_struct = FALSE;
- if (!ptk_findnextpickid(menuptr->menustid, PDIR_FORWARD, &eltno, &pickid))
- return;
- ptk_seteditmode(PEDIT_REPLACE);
- do
- {
- pset_elem_ptr(eltno);
- pset_pick_id(pickid + shiftby);
- if (menuptr->menutype == PTKEBOXMENU)
- {
- shift = get_tlboxcorner(pickid + shiftby);
- ptk_shift3(&shift, PTYPE_REPLACE, shiftmat);
- poffset_elem_ptr(1);
- pset_local_tran3(shiftmat, PTYPE_REPLACE);
- }
- eltno++;
- if (!ptk_findnextpickid(menuptr->menustid, PDIR_FORWARD, &eltno, &pickid))
- end_of_struct = TRUE;
- } while (!end_of_struct);
- ptk_unseteditmode();
- } /* shift_items */
-
- /*--------------------------------------------------------------------------*/
-
- static void delete_item(C(Pint) menustid, C(Pint) itemnum)
- PreANSI(Pint menustid)
- PreANSI(Pint itemnum)
- /*
- ** \parambegin
- ** \param{}{menustid}{menu structure id}{IN}
- ** \param{}{eltno}{element pointer of item}{IN}
- ** \paramend
- ** \blurb{Delete item from menu. }
- */
- {
- Pint elem1, elem2;
-
- finditemrange(menustid, itemnum, &elem1, &elem2);
- if (elem1 != -1)
- {
- ptk_openstruct(menustid);
- pdel_elem_range(elem1, elem2);
- ptk_closestruct();
- }
- } /* delete_item */
-
- /*--------------------------------------------------------------------------*/
-
- static ptkboolean find_string(C(Pint) structure, C(Pint *) pickid,
- C(char *) str)
- PreANSI(Pint structure)
- PreANSI(Pint *pickid)
- PreANSI(char *str)
- /*
- ** \parambegin
- ** \param{}{structure}{menu structure id}{IN}
- ** \param{}{pickid}{item containing string}{IN}
- ** \param{}{strmenu}{string and menu data}{IN}
- ** \paramend
- ** \blurb{Search for string in menu items.
- ** Returns TRUE if string found, otherwise FALSE.}
- */
- {
- Pint error;
- Psearch_status stat;
- ptkselcontent elcont;
- Pstore store;
- Pint eltptr;
- ptkboolean stop_search, string_found;
- Pint numelems;
- Pelem_type_list include, exclude;
- Pelem_type includeelems[10], excludeelems[10];
-
- eltptr = 0;
- stop_search = FALSE;
- string_found = FALSE;
- numelems = ptk_elemcount(structure);
- do
- {
- includeelems[0] = PELEM_TEXT3;
- includeelems[1] = PELEM_TEXT;
- includeelems[2] = PELEM_EXEC_STRUCT;
- includeelems[3] = PELEM_PICK_ID;
- include.num_elem_types = 4;
- include.elem_types = includeelems;
- exclude.num_elem_types = 0;
- exclude.elem_types = excludeelems;
-
- pelem_search(structure, eltptr, PDIR_FORWARD, &include, &exclude,
- &error, &stat, &eltptr);
-
- if (error != 0)
- stop_search = TRUE;
- else
- if (stat != PSEARCH_STATUS_SUCCESS)
- stop_search = TRUE;
- else
- {
- pcreate_store(&error, &store);
- ptk_inqelemtypesizecontent(structure, eltptr, store, &error, &elcont);
- if (error == 0)
- {
- switch (elcont.eltype)
- {
-
- case PELEM_TEXT:
- if (strcmp(elcont.eldata->text.char_string, str) == 0)
- string_found = TRUE;
- break;
-
- case PELEM_TEXT3:
- if (strcmp(elcont.eldata->text3.char_string, str) == 0)
- string_found = TRUE;
- break;
-
- case PELEM_EXEC_STRUCT:
- string_found = find_string(elcont.eldata->int_data, pickid, str);
- break;
-
- case PELEM_PICK_ID:
- *pickid = elcont.eldata->int_data;
- break;
- }
- }
- }
- eltptr++;
- ptk_delstore(store);
- } while (!string_found && !stop_search && (eltptr <= numelems));
- return string_found;
- } /* find_string */
-
- /*--------------------------------------------------------------------------*/
-
- static void redrawboxmenuitem(C(Pint) textcolour, C(Pint) intcolour,
- C(Pint) edgecolour, C(Pint) tlcolour,
- C(Pint) brcolour)
- PreANSI(Pint textcolour)
- PreANSI(Pint intcolour)
- PreANSI(Pint edgecolour)
- PreANSI(Pint tlcolour)
- PreANSI(Pint brcolour)
- {
- Ppoint3 box_centre;
- Pint err, elptr, lstnum;
- Ppoint centresize;
- Pelem_type eltype[2];
- Psearch_status stat;
-
- /* find elem = setintstyle */
- eltype[0] = PELEM_INT_STYLE;
- ptk_findelemtype(eltype, 1, PDIR_FORWARD, &stat, &elptr, &lstnum);
- /* delete next 9 elems */
- ptk_delelem(9);
- box_centre = ptk_point3(0.5 * menuptr->boxsize.x,
- -0.5 * menuptr->boxsize.y, 0.0);
- centresize = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- ptk_framebox(&box_centre, ¢resize, &menuptr->framesize,
- intcolour, edgecolour, tlcolour, brcolour);
- /* replace text colour if required */
- eltype[0] = PELEM_TEXT_COLR_IND;
- eltype[1] = PELEM_PICK_ID;
- ptk_findelemtype(eltype, 2, PDIR_FORWARD, &stat, &elptr, &lstnum);
- if ((stat == PSEARCH_STATUS_SUCCESS) && (lstnum == 0))
- {
- pdel_elem();
- pset_text_colr_ind(textcolour);
- }
- } /* redrawboxmenuitem */
-
- /*--------------------------------------------------------------------------*/
-
- static void resetcharheight()
- {
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "charheight"));
- poffset_elem_ptr(1);
- pdel_elem();
- pset_char_ht(menuptr->charheight);
- ptk_closestruct();
- } /* resetcharheight */
-
- /*--------------------------------------------------------------------------*/
-
- static void getmenulimits(C(Ppoint *) pos, C(Plimit *) lims)
- PreANSI(Ppoint *pos)
- PreANSI(Plimit *lims)
- {
- Pfloat xdimen, ydimen;
-
- xdimen = menuptr->boxsize.x; /* + (2.0 * menuptr->framesize.x); */
- ydimen = menuptr->boxsize.y; /* + (2.0 * menuptr->framesize.y); */
- *lims = ptk_limit(pos->x, pos->x, pos->y, pos->y);
- if (menuptr->menutype == PTKEBOXMENU)
- switch (menuptr->menupath)
- {
- case PPATH_RIGHT:
- lims->x_max += ((Pfloat)menuptr->maxitem * xdimen);
- lims->y_min -= ydimen;
- break;
-
- case PPATH_LEFT:
- lims->x_min -= (menuptr->maxitem - 1) * xdimen;
- lims->x_max += xdimen;
- lims->y_min -= ydimen;
- break;
-
- case PPATH_UP:
- lims->x_max += xdimen;
- lims->y_min -= ydimen;
- lims->y_max += ((Pfloat)(menuptr->maxitem - 1) * ydimen);
- break;
-
- case PPATH_DOWN:
- lims->x_max += xdimen;
- lims->y_min -= ((Pfloat)menuptr->maxitem * ydimen);
- break;
- }
- else
- {
- lims->x_max += xdimen / 2.0;
- lims->x_min -= xdimen / 2.0;
- lims->y_max += ydimen / 2.0;
- lims->y_min -= ydimen / 2.0;
- }
- } /* getmenulimits */
-
- /*--------------------------------------------------------------------------*/
- /*------------------- exported menu routines -------------------------------*/
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_createusermenu(C(Pint) menuid, C(Pint) menustid)
- PreANSI(Pint menuid)
- PreANSI(Pint menustid)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{menustid}{menu structure identifier}{IN}
- ** \paramend
- ** \blurb{This function creates a user menu using the structure
- ** {\tt menustid}. Each menu item must be an individual PHIGS
- ** structure or network and the menu initially contains no menu items.
- ** This function requires hashtables "label", "name".}
- */
- {
- ptksmenu *newmenu;
- Pint_list incl;
- Pint inclname;
- char stname[30];
- Pmatrix3 unitmat;
-
- setmenu(menuid);
- if (menuptr == NULL)
- {
- if (lastmenu == NULL)
- {
- firstmenu = lastmenu = newmenu =
- (ptksmenu *)malloc(sizeof(ptksmenu));
- newmenu->next = NULL;
- }
- else
- {
- lastmenu->next = newmenu = (ptksmenu *)malloc(sizeof(ptksmenu));
- newmenu->next = NULL;
- lastmenu = lastmenu->next;
- }
-
- menucount++;
- newmenu->menuid = menuid;
- newmenu->menustid = menustid;
- newmenu->maxitem = 0;
- newmenu->highlight = 0;
- newmenu->posted.num_ints = 0;
- newmenu->posted.ints = (Pint *)calloc(10, sizeof(Pint));
- sprintf(stname, "name$menu%d", menuid);
- newmenu->menuname = ptk_stringtoint("name", stname);
- ptk_openstruct(newmenu->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(0);
-
- newmenu->menutype = PTKEUSERMENU;
-
- incl.num_ints = 1;
- incl.ints = &inclname;
- incl.ints[0] = newmenu->menuname;
-
- plabel(ptk_stringtoint("label", "menuviewind"));
-
- plabel(ptk_stringtoint("label", "globaltran"));
- ptk_unitmatrix3(unitmat);
- pset_global_tran3(unitmat);
-
- padd_names_set(&incl);
- plabel(ptk_stringtoint("label", "begin-menu"));
-
- plabel(ptk_stringtoint("label", "end-menu"));
- premove_names_set(&incl);
- ptk_unseteditmode();
- ptk_closestruct();
- }
- } /* ptk_createusermenu */
-
- /*--------------------------------------------------------------------------*/
-
- static void createboxmenu(C(Pint) menuid,
- C(Ppoint *) tlcorner, C(Ppoint *) boxsize,
- C(Ptext_path) menupath, C(Pint) textcolour, C(Pint) intcolour,
- C(Pint) edgecolour, C(Pint) boxtlcolour, C(Pint) boxbrcolour)
- PreANSI(Pint menuid)
- PreANSI(Ppoint *tlcorner)
- PreANSI(Ppoint *boxsize)
- PreANSI(Ptext_path menupath)
- PreANSI(Pint textcolour)
- PreANSI(Pint intcolour)
- PreANSI(Pint edgecolour)
- PreANSI(Pint boxtlcolour)
- PreANSI(Pint boxbrcolour)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ppoint *}{tlcorner}{top left corner of menu}{IN}
- ** \param{Ppoint *}{boxsize}{width and height of menu box item}{IN}
- ** \param{Ptext_path}{menupath}{path of box menu (left, right, up, down)}{IN}
- ** \param{Pint}{textcolour}{colour index for text}{IN}
- ** \param{Pint}{intcolour}{colour index for interior}{IN}
- ** \param{Pint}{edgecolour}{colour index for edges}{IN}
- ** \param{Pint}{boxtlcolour}{colour index for top-left of box}{IN}
- ** \param{Pint}{boxcolour}{colour index for bottom-right of box}{IN}
- ** \paramend
- ** \blurb{Create a box menu using given specification.}
- */
- {
- Ptext_align align;
- Pmatrix3 mat;
- ptksmenu *newmenu;
- Pint_list wsids;
- Pint err, totlen, wsid;
- char stname[20], *str;
- Pint_list incl;
- Pint inclname, i, maxchars;
- Pfloat charheight, framedim;
- Ppoint3 pos;
-
- setmenu(menuid);
- if (menuptr == NULL)
- {
- if (lastmenu == NULL)
- {
- firstmenu = lastmenu = newmenu =
- (ptksmenu *)malloc(sizeof(ptksmenu));
- newmenu->next = NULL;
- }
- else
- {
- lastmenu->next = newmenu = (ptksmenu *)malloc(sizeof(ptksmenu));
- newmenu->next = NULL;
- lastmenu = lastmenu->next;
- }
-
- menucount++;
- newmenu->menuid = menuid;
- wsids.ints = &wsid;
- pinq_open_wss(1, 0, &err, &wsids, &totlen);
- newmenu->wsid = wsids.ints[0];
- newmenu->font = 1;
- newmenu->highlight = 0;
- newmenu->posted.num_ints = 0;
- newmenu->posted.ints = (Pint *)calloc(10, sizeof(Pint));
- sprintf(stname, "ptk$menu%d", menuid);
- newmenu->menustid = ptk_stringtoint("structureid", stname);
- sprintf(stname, "name$menu%d", menuid);
- newmenu->menuname = ptk_stringtoint("name", stname);
- newmenu->menutype = PTKEBOXMENU;
- newmenu->boxsize = *boxsize;
- newmenu->menupath = menupath;
- newmenu->menuposition = *tlcorner;
- newmenu->maxitem = 0;
- newmenu->charheight = 100.0;
- newmenu->longstr[0] = '\0';
- newmenu->intcolour = intcolour;
- newmenu->edgecolour = edgecolour;
- newmenu->tlcolour = boxtlcolour;
- newmenu->brcolour = boxbrcolour;
- newmenu->textcolour = textcolour;
- newmenu->htintcolour = textcolour;
- newmenu->htedgecolour = edgecolour;
- newmenu->httextcolour = intcolour;
- newmenu->httlcolour = boxbrcolour;
- newmenu->htbrcolour = boxtlcolour;
-
- framedim = 0.05 * PTKMIN(boxsize->x, boxsize->y);
- newmenu->framesize = ptk_point(framedim, framedim);
-
- incl.num_ints = 1;
- incl.ints = &inclname;
- incl.ints[0] = newmenu->menuname;
-
- ptk_openstruct(newmenu->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- padd_names_set(&incl);
-
- plabel(ptk_stringtoint("label", "menuviewind"));
-
- plabel(ptk_stringtoint("label", "globaltran"));
- pos = ptk_point3(tlcorner->x, tlcorner->y, 0.0);
- ptk_shift3(&pos, PTYPE_REPLACE, mat);
- pset_global_tran3(mat);
- /* calculate text expan */
- pset_text_prec(PPREC_STROKE);
- plabel(ptk_stringtoint("label", "charheight"));
- charheight = 0.01;
- pset_char_ht(charheight);
- pset_text_font(1);
- align.hor = PHOR_CTR;
- align.vert = PVERT_HALF;
- pset_text_align(&align);
- plabel(ptk_stringtoint("label", "begin-menu"));
-
- plabel(ptk_stringtoint("label", "end-menu"));
- premove_names_set(&incl);
- ptk_unseteditmode();
- ptk_closestruct();
- }
- } /* createboxmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_createboxmenu(C(Pint) menuid,
- C(Ppoint *) tlcorner, C(Ppoint *) boxsize)
- PreANSI(Pint menuid)
- PreANSI(Ppoint *tlcorner)
- PreANSI(Ppoint *boxsize)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ppoint *}{tlcorner}{top left corner of menu}{IN}
- ** \param{Ppoint *}{boxsize}{width and height of menu box item}{IN}
- ** \paramend
- ** \blurb{This function creates a box menu with no initial items.
- ** The position of the menu is specified by {\tt tlcorner} which
- ** defines the top-left corner of the first menu item. The position
- ** and size of box menu items are given in the range [0, 1]. The default
- ** menu path is DOWN.
- ** This function requires hashtables "structureid", "label", "name".}
- */
- {
- createboxmenu(menuid, tlcorner, boxsize, PPATH_DOWN, 1, 0, 1, 1, 1);
- } /* ptk_createboxmenu */
-
- /*--------------------------------------------------------------------------*/
-
- static void insertboxtextitem(C(Pint) eltno, C(char *) str, C(Pint) itemnum)
- PreANSI(Pint eltno)
- PreANSI(char *str)
- PreANSI(Pint itemnum)
- /*
- ** \parambegin
- ** \param{Pint}{eltno}{element pointer}{IN}
- ** \param{}{menubox}{menu item description data}{IN}
- ** \paramend
- ** \blurb{Add item to box menu.}
- */
- {
- Pmatrix3 matrix, shiftmat;
- Pfloat scl, charheight;
- Ppoint3 box_centre;
- Ppoint3 tlpt;
- Pint err;
- Plimit3 boundbox, itembox;
- Ppoint centresize, txpt;
-
- pset_elem_ptr(eltno);
- pset_pick_id(itemnum);
- tlpt = get_tlboxcorner(itemnum);
- ptk_shift3(&tlpt, PTYPE_REPLACE, shiftmat);
- pset_local_tran3(shiftmat, PTYPE_REPLACE);
-
- box_centre = ptk_point3(0.5 * menuptr->boxsize.x,
- -0.5 * menuptr->boxsize.y, 0.0);
- centresize = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- ptk_framebox(&box_centre, ¢resize, &menuptr->framesize,
- menuptr->intcolour, menuptr->edgecolour,
- menuptr->tlcolour, menuptr->brcolour);
-
- /* recalculate character height if necessary */
- ptk_computecharheight(menuptr->wsid, str, ¢resize, menuptr->font,
- &charheight);
- if (charheight < menuptr->charheight)
- {
- strcpy(menuptr->longstr, str);
- menuptr->charheight = charheight;
- resetcharheight();
- }
- pset_text_colr_ind(menuptr->textcolour);
- txpt = ptk_point(box_centre.x, box_centre.y);
- ptext(&txpt, str);
- } /* insertboxtextitem */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_createtextmenuitem(C(Pint) menuid, C(char *) str,
- C(Pint) itemno, C(Pedit_mode) editmode, C(Pint *) error)
- PreANSI(Pint menuid)
- PreANSI(char *str)
- PreANSI(Pint itemno)
- PreANSI(Pedit_mode editmode)
- PreANSI(Pint *error)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{char *}{str}{text string}{IN}
- ** \param{Pint}{itemno}{menu item number}{IN}
- ** \param{Pedit\_mode}{editmode}{insert or replace menu item.}{IN}
- ** \param{Pint *}{error}{error code}{IN}
- ** \paramend
- ** \blurb{This function creates a box menu item containing the character
- ** string {\tt str}. The string is automatically scaled to fit inside
- ** the menu item box. This function may only be used with box menus.
- ** The error code = 1 if {\tt menuid} doesn't exist and = 2 if the
- ** menu is not a box menu.}
- */
- {
- Pint elt;
- Pint itemalreadythere;
-
- /* check menu name supplied, if it has no prefix add current structure
- ** prefix.
- */
-
- *error = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- ptk_seteditmode(PEDIT_INSERT);
- ptk_openstruct(menuptr->menustid);
- if (menuptr->menutype != PTKEBOXMENU)
- *error = 2;
- else
- {
- find_insertion_pt(menuptr->menustid, itemno, &elt, &itemalreadythere);
- if (itemalreadythere == itemno)
- {
- if (editmode == PEDIT_INSERT) /* shift following items up by one */
- shift_items(elt, 1);
- else /* mode is replace, therefore delete old item */
- delete_item(menuptr->menustid, itemno);
- }
- /* add new item before elt */
- insertboxtextitem(elt - 1, str, itemno);
- if (itemno > menuptr->maxitem)
- menuptr->maxitem = itemno;
- }
- ptk_closestruct();
- ptk_unseteditmode();
- }
- else
- *error = 1;
- } /* ptk_createtextmenuitem */
-
- /*--------------------------------------------------------------------------*/
-
- static void insertboxstructitem(C(Pint) eltno, C(Pint) stid, C(Pint) itemnum)
- PreANSI(Pint eltno)
- PreANSI(Pint stid)
- PreANSI(Pint itemnum)
- /*
- ** \parambegin
- ** \param{Pint}{eltno}{element pointer}{IN}
- ** \param{}{menubox}{menu item description data}{IN}
- ** \paramend
- ** \blurb{Add item to box menu.}
- */
- {
- Pmatrix3 matrix, shiftmat;
- Pfloat scl, charheight;
- Ppoint3 box_centre;
- Ppoint3 tlpt;
- Pint err;
- Plimit3 boundbox, itembox;
- Ppoint centresize, txpt;
-
- pset_elem_ptr(eltno);
- pset_pick_id(itemnum);
- tlpt = get_tlboxcorner(itemnum);
- ptk_shift3(&tlpt, PTYPE_REPLACE, shiftmat);
- pset_local_tran3(shiftmat, PTYPE_REPLACE);
- box_centre = ptk_point3(0.5 * menuptr->boxsize.x,
- -0.5 * menuptr->boxsize.y, 0.0);
- centresize = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- ptk_framebox(&box_centre, ¢resize, &menuptr->framesize,
- menuptr->intcolour, menuptr->edgecolour,
- menuptr->tlcolour, menuptr->brcolour);
- if (ptk_boundingbox(stid, &boundbox, TRUE))
- {
- itembox = ptk_limit3(0.0, menuptr->boxsize.x,
- -menuptr->boxsize.y, 0.0, 0.0, 1.0);
- ptk_box3tobox3(&boundbox, &itembox, FALSE, PTYPE_REPLACE, matrix, &err);
- pset_local_tran3(matrix, PTYPE_PRECONCAT);
- pexec_struct(stid);
- }
- } /* insertboxstructitem */
-
- /*--------------------------------------------------------------------------*/
-
- static void insertuseritem(C(Pint) eltno, C(Pint) stid, C(Pint) itemnum)
- PreANSI(Pint eltno)
- PreANSI(Pint stid)
- PreANSI(Pint itemnum)
- /*
- ** \parambegin
- ** \param{Pint}{eltno}{element pointer}{IN}
- ** \param{}{usermenu}{menu item description data}{IN}
- ** \paramend
- ** \blurb{Add user menu item to currently open structure.}
- */
- {
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(eltno);
- pset_pick_id(itemnum);
- pexec_struct(stid);
- ptk_unseteditmode();
- } /* insertuseritem */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_createstructmenuitem(C(Pint) menuid, C(Pint) structure,
- C(Pint) itemno, C(Pedit_mode) editmode, C(Pint *) error)
- PreANSI(Pint menuid)
- PreANSI(Pint structure)
- PreANSI(Pint itemno)
- PreANSI(Pedit_mode editmode)
- PreANSI(Pint *error)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{structure}{menu item structure identifier}{IN}
- ** \param{Pint}{itemno}{menu item number}{IN}
- ** \param{Pedit\_mode}{editmode}{insert or replace menu item}{IN}
- ** \param{Pint *}{error}{error code}{IN}
- ** \paramend
- ** \blurb{This function creates a menu item defined by {\tt structure}.
- ** In the case of box menus the structure is mapped into the item box
- ** with aspect ratio preserved. No transformation is applied for user
- ** menu items. The error code = 1 if {\tt menuid} doesn't exist.}
- */
- {
- Pint elt;
- Pint itemalreadythere;
-
- *error = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- ptk_openstruct(menuptr->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- {
-
- find_insertion_pt(menuptr->menustid, itemno, &elt, &itemalreadythere);
- if (itemalreadythere == itemno)
- {
- if (editmode == PEDIT_INSERT) /* shift following items up by one */
- shift_items(elt, 1);
- else /* mode is replace, therefore delete old item */
- delete_item(menuptr->menustid, itemno);
- }
- /* add new item before elt */
- if ((menuptr->menutype == PTKEUSERMENU) ||
- (menuptr->menutype == PTKEROTATOR))
- insertuseritem(elt - 1, structure, itemno);
- else
- insertboxstructitem(elt - 1, structure, itemno);
- if (itemno > menuptr->maxitem)
- menuptr->maxitem = itemno;
- }
- ptk_unseteditmode();
- ptk_closestruct();
- }
- else
- *error = 1;
- } /* ptk_createstructmenuitem */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_delmenu(C(Pint) menuid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function deletes a menu from the PHIGS Toolkit menu store.
- ** The function returns TRUE if {\tt menuid} is deleted, otherwise FALSE.}
- */
- {
- ptksmenu *ptr, *junk;
- char stname[20];
- Pint i;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- for (i = 0; i < menuptr->posted.num_ints; i++)
- ptk_unpostmenu(menuptr->posted.ints[i], menuid);
- pdel_struct(menuptr->menustid);
- ptr = firstmenu;
- if (ptr->menuid == menuid)
- {
- firstmenu = firstmenu->next;
- if (lastmenu->menuid == menuid)
- lastmenu = firstmenu;
- free(ptr);
- }
- else
- {
- while (ptr->next->menuid != menuid)
- {
- ptr = ptr->next;
- if (ptr->next == NULL)
- return FALSE;
- }
- junk = ptr->next;
- ptr->next = junk->next;
- free(junk);
- if (ptr->next == NULL)
- lastmenu = ptr;
- }
- /* delete strings */
- sprintf(stname, "name$menu%d", menuid);
- ptk_delstring("name", stname);
- sprintf(stname, "ptk$menu%d", menuid);
- ptk_delstring("structureid", stname);
- menucount--;
- return TRUE;
- }
- else
- return FALSE;
- } /* ptk_delmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_delmenuitem(C(Pint) menuid, C(Pint) itemno)
- PreANSI(Pint menuid)
- PreANSI(Pint itemno)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{itemno}{menu item to delete}{IN}
- ** \paramend
- ** \blurb{This function deletes the menu item {\tt itemno}.
- ** The function returns TRUE if the menu item is deleted, otherwise FALSE.}
- */
- {
- Pint elptr, lstnum, err, numelems;
- Pfloat charheight, minheight;
- Pstore store;
- Pelem_type eltype;
- Psearch_status stat;
- ptkselcontent elcont;
- Ppoint centresize;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (!find_item(menuptr->menustid, itemno, &elptr))
- {
- return FALSE;
- }
- ptk_openstruct(menuptr->menustid);
- delete_item(menuptr->menustid, itemno);
- shift_items(elptr, -1);
- ptk_closestruct();
- if (menuptr->menutype == PTKEBOXMENU)
- {
- /* reset charheight to longest item string.
- ** search for all PELEM_TEXT elements in menu structure and
- ** set charheight to cater for the longest
- */
- numelems = ptk_elemcount(menuptr->menustid);
- ptk_openstruct(menuptr->menustid);
- elptr = 0;
- eltype = PELEM_TEXT;
- minheight = 100.0;
- centresize = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- do
- {
- pset_elem_ptr(elptr);
- ptk_findelemtype(&eltype, 1, PDIR_FORWARD, &stat, &elptr, &lstnum);
- if (stat == PSEARCH_STATUS_SUCCESS)
- {
- pcreate_store(&err, &store);
- ptk_inqelemtypesizecontent(menuptr->menustid, elptr, store, &err,
- &elcont);
- ptk_computecharheight(menuptr->wsid,
- elcont.eldata->text.char_string,
- ¢resize, menuptr->font, &charheight);
- if (charheight < minheight)
- {
- strcpy(menuptr->longstr, elcont.eldata->text.char_string);
- minheight = charheight;
- }
- ptk_delstore(store);
- }
- elptr++;
- } while ((stat == PSEARCH_STATUS_SUCCESS) && (elptr <= numelems));
- ptk_closestruct();
- if (minheight < 100.0)
- {
- menuptr->charheight = minheight;
- resetcharheight();
- }
- }
- return TRUE;
- }
- else
- return FALSE;
- } /* ptk_delmenuitem */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_frontmenu(C(Pint) wsid, C(Pint) menuid)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function sets the post priority of the menu structure
- ** so that it is displayed on top of all the other posted menus and
- ** windows.}
- */
- {
- Pint ind, err, frontwindow, backwindow, frontwindowstid, fronticonstid;
- ptkboolean windows;
- ptkewindowstate frontstate, backstate;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- checkws(wsid);
- findwsid(wsid, &ind);
- windows = ptk_inqfrontbackwindowid(wsid, &frontwindow, &frontstate,
- &backwindow, &backstate, &err);
- if (!wsmenus[ind].postedmenus)
- {
- if (windows)
- {
- ptk_inqwindowstructid(frontwindow, &frontwindowstid, &fronticonstid,
- &err);
- if (frontstate == PTKEWINDOWOPEN)
- ptk_postrelative(wsid, menuptr->menustid, PPRI_HIGHER,
- frontwindowstid, &err);
- else
- ptk_postrelative(wsid, menuptr->menustid, PPRI_HIGHER,
- fronticonstid, &err);
- }
- else
- ppost_struct(wsid, menuptr->menustid, 0.0);
- wsmenus[ind].frontptr = wsmenus[ind].backptr = menuptr;
- wsmenus[ind].postedmenus = TRUE;
- }
- else
- {
- ptk_postrelative(wsid, menuptr->menustid, PPRI_HIGHER,
- wsmenus[ind].frontptr->menustid, &err);
- wsmenus[ind].frontptr = menuptr;
- if (menuptr == wsmenus[ind].backptr)
- findback(wsid, &wsmenus[ind]);
- }
- addtointlst(wsid, &menuptr->posted);
- }
- } /* ptk_frontmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_backmenu(C(Pint) wsid, C(Pint) menuid)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function sets the post priority of the menu structure so
- ** that it is displayed below all other posted menus but in front of
- ** all posted windows.}
- */
- {
- Pint ind, err, frontwindow, backwindow, frontwindowstid, fronticonstid;
- ptkboolean windows;
- ptkewindowstate frontstate, backstate;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- checkws(wsid);
- findwsid(wsid, &ind);
- windows = ptk_inqfrontbackwindowid(wsid, &frontwindow, &frontstate,
- &backwindow, &backstate, &err);
- if (windows)
- {
- ptk_inqwindowstructid(frontwindow, &frontwindowstid, &fronticonstid,
- &err);
- if (frontstate == PTKEWINDOWOPEN)
- ptk_postrelative(wsid, menuptr->menustid, PPRI_HIGHER,
- frontwindowstid, &err);
- else
- ptk_postrelative(wsid, menuptr->menustid, PPRI_HIGHER,
- fronticonstid, &err);
- }
- else
- if (!wsmenus[ind].postedmenus)
- ppost_struct(wsid, menuptr->menustid, 0.0);
- else
- ptk_postrelative(wsid, menuptr->menustid, PPRI_LOWER,
- wsmenus[ind].backptr->menustid, &err);
- if (!wsmenus[ind].postedmenus)
- {
- wsmenus[ind].frontptr = wsmenus[ind].backptr = menuptr;
- wsmenus[ind].postedmenus = TRUE;
- }
- else
- {
- wsmenus[ind].backptr = menuptr;
- if (menuptr == wsmenus[ind].frontptr)
- findfront(wsid, &wsmenus[ind]);
- }
- addtointlst(wsid, &menuptr->posted);
- }
- } /* ptk_backmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_postmenu(C(Pint) wsid, C(Pint) menuid)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function posts the menu structure to the workstation
- ** {\tt wsid}. The priority of the menu structure is controlled by the
- ** PHIGS Toolkit menu system to provide an ordered stacking of displayed
- ** menus. When {\tt menuid} is posted it becomes the front menu.}
- */
- {
- ptk_frontmenu(wsid, menuid);
- } /* ptk_postmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_unpostmenu(C(Pint) wsid, C(Pint) menuid)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function unposts a menu structure from the workstation
- ** {\tt wsid}. The front and back menus are updated if necessary.}
- */
- {
- Pint ind;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- findwsid(wsid, &ind);
- punpost_struct(wsid, menuptr->menustid);
- if (menuptr == wsmenus[ind].backptr)
- findback(wsid, &wsmenus[ind]);
- if (menuptr == wsmenus[ind].frontptr)
- findfront(wsid, &wsmenus[ind]);
- removefromintlst(wsid, &menuptr->posted);
- }
- } /* ptk_unpostmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_unpostallmenu(C(Pint) wsid)
- PreANSI(Pint wsid)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function unposts all menus from the workstation {\tt wsid}.}
- */
- {
- ptksmenu *ptrmenu;
-
- ptrmenu = firstmenu;
- while (ptrmenu != NULL)
- {
- if (inintlst(wsid, &ptrmenu->posted) != -1)
- ptk_unpostmenu(wsid, ptrmenu->menuid);
- ptrmenu = ptrmenu->next;
- }
- } /* ptk_unpostallmenu */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_stringscanmenus(C(Pint) wsid, C(char *) str,
- C(Pint *) menuid, C(Pint *) itemnum)
- PreANSI(Pint wsid)
- PreANSI(char *str)
- PreANSI(Pint *menuid)
- PreANSI(Pint *itemnum)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{char *}{str}{string}{IN}
- ** \param{Pint *}{menuid}{menu identifier}{OUT}
- ** \param{Pint *}{itemno}{item number}{OUT}
- ** \paramend
- ** \blurb{This function compares the character string {\tt str} with
- ** the items of all posted menus. The comparison begins with the
- ** highest priority menu and works through to the back menu.
- ** User menu items are also searched for text primitives with which to
- ** compare the string. The comparison is case sensitive so that
- ** "item 1" is not the same as "IteM 1".
- ** The function returns TRUE if the string matches a menu item,
- ** otherwise FALSE.}
- */
- {
- ptkboolean menufound;
- Pint_list *menus;
- ptksmenu *ptrmenu;
- Pint numstructs, i, err;
- Pposted_struct_list structlist;
- Pfilter *invisfilt;
- Pstore store;
-
- menufound = FALSE;
- structlist.postings = NULL;
- pinq_posted_structs(wsid, 0, 0, &err, &structlist, &numstructs);
- structlist.postings = (Pposted_struct *)calloc(numstructs,
- sizeof(Pposted_struct));
- pinq_posted_structs(wsid, numstructs, 0, &err, &structlist, &numstructs);
-
- /* inquire invisibility filter */
- pcreate_store(&err, &store);
- pinq_invis_filter(wsid, store, &err, &invisfilt);
-
- /* This bit is a bit dodgy because it relies on structlist being ordered
- ** by PHIGS into highest priority last. This is not standard PHIGS,
- ** so if version is not sorted do a sort.
- */
- i = numstructs - 1;
- while ((i >= 0) && (!menufound))
- {
- if (ismenu(structlist.postings[i].id, &ptrmenu))
- {
- /* check invisibility filter */
- if (!((inintlst(ptrmenu->menuname, &invisfilt->incl_set) != -1) &&
- (inintlst(ptrmenu->menuname, &invisfilt->excl_set) == -1)))
- {
- if (find_string(ptrmenu->menustid, itemnum, str))
- {
- menufound = TRUE;
- *menuid = ptrmenu->menuid;
- }
- }
- }
- i--;
- }
- free(structlist.postings);
- ptk_delstore(store);
- return menufound;
- } /* ptk_stringscanmenus */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_pickscanmenus(C(Ppick_path *) pickpath,
- C(Ppath_order) pathorder, C(Pint *) menuid, C(Pint *) itemnum)
- PreANSI(Ppick_path *pickpath)
- PreANSI(Ppath_order pathorder)
- PreANSI(Pint *menuid)
- PreANSI(Pint *itemnum)
- /*
- ** \parambegin
- ** \param{Ppick\_path *}{pickpath}{path through structure network.}{IN}
- ** \param{Ppath\_order}{pathorder}{order of data in pickpath}{IN}
- ** \param{Pint *}{menuid}{menu identifier}{OUT}
- ** \param{Pint *}{itemnum}{item number}{OUT}
- ** \paramend
- ** \blurb{This function tests the pick path to inquire if a menu item
- ** was picked.
- ** The function returns TRUE if a menu item was picked, otherwise FALSE.}
- */
- {
- Pint menustid;
-
- if (pathorder == PORDER_TOP_FIRST)
- {
- *itemnum = pickpath->path_list[pickpath->depth - 1].pick_id;
- menustid = pickpath->path_list[0].struct_id;
- return (getmenuid(menustid, menuid));
- }
- else
- {
- *itemnum = pickpath->path_list[0].pick_id;
- menustid = pickpath->path_list[pickpath->depth - 1].struct_id;
- return (getmenuid(menustid, menuid));
- }
- } /* ptk_pickscanmenus */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_locscanmenus(C(Pint) wsid, C(Ppoint *) point,
- C(Pint *) menuid, C(Pint *) itemnum, C(Ppoint *) value)
- PreANSI(Pint wsid)
- PreANSI(Ppoint *point)
- PreANSI(Pint *menuid)
- PreANSI(Pint *itemnum)
- PreANSI(Ppoint *value)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Ppoint *}{point}{input point}{IN}
- ** \param{Pint *}{menuid}{menu identifier}{OUT}
- ** \param{Pint *}{itemnum}{item number}{OUT}
- ** \param{Ppoint *}{value}{position of point within item}{OUT}
- ** \paramend
- ** \blurb{This function uses the INCREMENTAL SPATIAL SEARCH function
- ** of PHIGS to test if {\tt point} lies within a posted menu.
- ** The menus are tested begining the highest priority menu and working
- ** through to the back menu. The position of {\tt point} relative
- ** to bottom-left corner of the menu item bounding box is returned
- ** in {\tt value}.
- ** The function returns TRUE if {\tt point} lies within a menu,
- ** otherwise FALSE.}
- */
- {
- /* Implementation dependent code because HP doesn't support
- ** INCREMENTAL SPATIAL SEARCH. For HP simulate the search by
- ** using bounding boxes.
- */
- ptkboolean menufound, itemfound;
- ptksmenu *ptrmenu;
- Pint foundstruct;
- Pint elemno, pickid, firstpick, nextpick, nextpickid;
- Pfloat div;
- Plimit3 menubox;
- Pelem_type extype;
- Psearch_status status;
- Pint ptrlist[2];
- Pint_list elemlist;
- Pint numstructs, i, err;
- Pposted_struct_list structlist;
- Ppoint3 minbox, maxbox;
- Pmatrix3 mat;
- Pstore store;
- Pfilter *invisfilt;
- #ifdef SUN
- Pelem_ref_list reflist, startlist;
- Pelem_ref startpath;
- Pint ceiling;
- Pfilter_list normal, invert;
- Pfilter filter;
- Pfloat distance;
- Pint totlen, len;
-
- startlist.num_elem_refs = 1;
- startlist.elem_refs = &startpath;
- startpath.elem_pos = 0;
- ceiling = 1; /* all of structure network */
- normal.num_filters = 1;
- normal.filters = &filter;
- filter.incl_set.num_ints = 1;
- filter.excl_set.num_ints = 0;
- filter.excl_set.ints = NULL;
- invert.num_filters = 0;
- invert.filters = NULL;
- distance = 0.001; /* nearness to point */
- reflist.num_elem_refs = 0;
- reflist.elem_refs = NULL;
- #endif
- ptk_stacktsl();
- ptk_stackbbox();
- menufound = FALSE;
- structlist.postings = NULL;
- /* inquire posted structures */
- pinq_posted_structs(wsid, 0, 0, &err, &structlist, &numstructs);
- structlist.postings = (Pposted_struct *)calloc(numstructs,
- sizeof(Pposted_struct));
- pinq_posted_structs(wsid, numstructs, 0, &err, &structlist, &numstructs);
-
- /* inquire invisibility filter */
- pcreate_store(&err, &store);
- pinq_invis_filter(wsid, store, &err, &invisfilt);
-
- /* This bit is a bit dodgy because it relies on structlist being ordered
- ** by PHIGS into highest priority last. This is not standard PHIGS,
- ** so if version is not sorted do a sort.
- ** HP orders with highest priority first.
- ** PEXSI orders same as SUN.
- */
- #ifndef HP
- /* do for SUN and PEXSI */
- i = numstructs - 1;
- while ((i >= 0) && (!menufound))
- #endif
- #ifdef HP
- i = 0;
- while ((i < numstructs) && (!menufound))
- #endif
- {
- if (ismenu(structlist.postings[i].id, &ptrmenu))
- {
- /* check invisibility filter */
- if (!((inintlst(ptrmenu->menuname, &invisfilt->incl_set) != -1) &&
- (inintlst(ptrmenu->menuname, &invisfilt->excl_set) == -1)))
- {
- #ifdef SUN
- startpath.struct_id = ptrmenu->menustid;
- filter.incl_set.ints = &ptrmenu->menuname;
-
- pincr_spa_search(point, distance, &startlist, PIND_NO_CLIP,
- ceiling, &normal, &invert, 0, 0, &err,
- &reflist, &totlen);
- reflist.elem_refs = (Pelem_ref *)calloc(totlen, sizeof(Pelem_ref));
- pincr_spa_search(point, distance, &startlist, PIND_NO_CLIP,
- ceiling, &normal, &invert, totlen, 0, &err,
- &reflist, &totlen);
- *itemnum = 0;
- if (reflist.num_elem_refs > 0)
- {
- menufound = TRUE;
- *menuid = ptrmenu->menuid;
- *value = ptk_point(0.0, 0.0);
- foundstruct = reflist.elem_refs[0].struct_id;
- elemno = reflist.elem_refs[0].elem_pos;
- if (ptk_findnextpickid(foundstruct, PDIR_BACKWARD, &elemno,
- &pickid))
- *itemnum = pickid;
- firstpick = 1;
- ptk_findnextpickid(foundstruct, PDIR_FORWARD, &firstpick, &pickid);
-
- /* inquire TSL from element 1 to firstpick in foundstruct */
- ptk_inittsl();
- ptk_tsltraverserange(foundstruct, 1, foundstruct, firstpick, FALSE);
- nextpick = elemno + 1;
- if (!ptk_findnextpickid(foundstruct, PDIR_FORWARD, &nextpick,
- &pickid))
- nextpick = ptk_elemcount(foundstruct);
- ptk_initbbox();
- ptk_tsltraverserange(foundstruct, elemno, foundstruct, nextpick,
- TRUE);
- ptk_inqboundingbox(&menubox);
- /* calculate value */
- div = menubox.x_max - menubox.x_min;
- if (div != 0.0)
- value->x = (point->x - menubox.x_min)/div;
- div = menubox.y_max - menubox.y_min;
- if (div != 0.0)
- value->y = (point->y - menubox.y_min)/div;
- free(reflist.elem_refs);
- }
- #endif
- #ifndef SUN
- /* do for HP and PEXSI */
- foundstruct = ptrmenu->menustid;
- elemno = firstpick = 1;
- ptk_findnextpickid(foundstruct, PDIR_FORWARD, &firstpick, &pickid);
- ptk_inittsl();
- ptk_tsltraverserange(foundstruct, 1, foundstruct, firstpick, FALSE);
- ptk_boundingbox(foundstruct, &menubox, TRUE);
- if (ptinlimit3(point, &menubox))
- {
- menufound = TRUE;
- *menuid = ptrmenu->menuid;
- itemfound = FALSE;
- while (!itemfound)
- {
- ptk_stacktsl();
- ptk_stackbbox();
- if (ptk_findnextpickid(foundstruct, PDIR_FORWARD, &elemno,
- &pickid))
- {
- elemlist.num_ints = 2;
- elemlist.ints = ptrlist;
- ptrlist[0] = elemno;
- nextpick = elemno + 1;
- if (!ptk_findnextpickid(foundstruct, PDIR_FORWARD, &nextpick,
- &nextpickid))
- nextpick = ptk_elemcount(foundstruct);
- ptk_initbbox();
- ptk_tsltraverserange(foundstruct, elemno, foundstruct,
- nextpick, TRUE);
- ptk_inqboundingbox(&menubox);
- if (ptinlimit3(point, &menubox))
- {
- itemfound = TRUE;
- *itemnum = pickid;
- /* calculate value */
- *value = ptk_point(0.0, 0.0);
- div = menubox.x_max - menubox.x_min;
- if (div != 0.0)
- value->x = (point->x - menubox.x_min)/div;
- div = menubox.y_max - menubox.y_min;
- if (div != 0.0)
- value->y = (point->y - menubox.y_min)/div;
- }
- else
- elemno++;
- }
- else
- {
- itemfound = TRUE;
- *itemnum = 0;
- }
- ptk_unstackbbox();
- ptk_unstacktsl();
- }
- }
- #endif
- }
- }
- #ifndef HP
- /* do for SUN and PEXSI */
- i--;
- #endif
- #ifdef HP
- i++;
- #endif
- }
- free(structlist.postings);
- ptk_delstore(store);
- ptk_unstackbbox();
- ptk_unstacktsl();
- return menufound;
- } /* ptk_locscanmenus */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_scanmenus(C(Pint) wsid, C(ptksgeneralinput *) input,
- C(ptksmenuoutput *) output)
- PreANSI(Pint wsid)
- PreANSI(ptksgeneralinput *input)
- PreANSI(ptksmenuoutput *output)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{ptksgeneralinput *}{input}{input data}{IN}
- ** \param{ptksmenuoutput *}{output}{output data}{IN}
- ** \paramend
- ** \blurb{This function performs a scan on all posted menus using
- ** either string, pick or locator data.
- ** The function returns TRUE if a menu item has been selected,
- ** otherwise FALSE.}
- */
- {
- ptkboolean result;
-
- switch (input->inputclass)
- {
-
- case PIN_LOC:
- result = ptk_locscanmenus(wsid, &input->ptkugeninput.locpoint,
- &output->menuid, &output->itemnum, &output->value);
- output->measure = TRUE;
- break;
-
- case PIN_STROKE:
- result = FALSE;
- break;
-
- case PIN_VAL:
- result = FALSE;
- break;
-
- case PIN_CHOICE:
- result = FALSE;
- break;
-
- case PIN_PICK:
- result = ptk_pickscanmenus(&input->ptkugeninput.ptkspickinput.pickdata,
- input->ptkugeninput.ptkspickinput.pathorder,
- &output->menuid, &output->itemnum);
- output->measure = FALSE;
- break;
-
- case PIN_STRING:
- result = ptk_stringscanmenus(wsid, input->ptkugeninput.str,
- &output->menuid, &output->itemnum);
- output->measure = FALSE;
- break;
- }
- return result;
- } /* ptk_scanmenus */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setmenuposition(C(Pint) menuid, C(Ppoint *) menupos)
- PreANSI(Pint menuid)
- PreANSI(Ppoint *menupos)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ppoint *}{menupos}{menu position}{IN}
- ** \paramend
- ** \blurb{This function sets the position of the top-left corner of the
- ** first menu item. The position is given in the range [0, 1]. If the
- ** position results in part of the menu being clipped then the actual
- ** position is adjusted so that as much as possible of the menu is
- ** visible.}
- */
- {
- Ppoint pos;
- Ppoint3 mpos;
- Pmatrix3 mat;
- Plimit lim;
-
- pos = *menupos;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if ((menuptr->menutype == PTKEBOXMENU) ||
- (menuptr->menutype == PTKEROTATOR))
- {
- getmenulimits(menupos, &lim);
- if ((lim.x_min < 0.0) && (lim.x_max > 1.0))
- { /* do nothing */ }
- else
- if ((lim.y_min < 0.0) && (lim.y_max > 1.0))
- { /* do nothing */ }
- else
- if ((lim.x_min < 0.0) && (lim.y_min < 0.0))
- {
- /* bottom left */
- pos.x += PTKMIN(1.0 - lim.x_max, -lim.x_min);
- pos.y += PTKMIN(1.0 - lim.y_max, -lim.y_min);
- }
- else
- if ((lim.x_min < 0.0) && (lim.y_max > 1.0))
- {
- /* top left */
- pos.x += PTKMIN(1.0 - lim.x_max, -lim.x_min);
- pos.y -= PTKMIN(lim.y_min, lim.y_max - 1.0);
- }
- else
- if ((lim.x_max > 1.0) && (lim.y_min < 0.0))
- {
- /* bottom right */
- pos.x -= PTKMIN(lim.x_min, lim.x_max - 1.0);
- pos.y += PTKMIN(1.0 - lim.y_max, -lim.y_min);
- }
- else
- if ((lim.x_max > 1.0) && (lim.y_max > 1.0))
- {
- /* top right */
- pos.x -= PTKMIN(lim.x_min, lim.x_max - 1.0);
- pos.y -= PTKMIN(lim.y_min, lim.y_max - 1.0);
- }
- else
- if (lim.x_min < 0.0)
- pos.x += PTKMIN(1.0 - lim.x_max, -lim.x_min);
- else
- if (lim.x_max > 1.0)
- pos.x -= PTKMIN(lim.x_min, lim.x_max - 1.0);
- else
- if (lim.y_min < 0.0)
- pos.y += PTKMIN(1.0 - lim.y_max, -lim.y_min);
- else
- if (lim.y_max > 1.0)
- pos.y -= PTKMIN(lim.y_min, lim.y_max - 1.0);
- }
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "globaltran"));
- poffset_elem_ptr(1);
- pdel_elem();
- mpos = ptk_point3(pos.x, pos.y, 0.0);
- ptk_shift3(&mpos, PTYPE_REPLACE, mat);
- pset_global_tran3(mat);
- ptk_closestruct();
- menuptr->menuposition = pos;
- }
- } /* ptk_setmenuposition */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setboxmenutextfont(C(Pint) wsid, C(Pint) menuid,
- C(Pint) font)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- PreANSI(Pint font)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{font}{text font}{IN}
- ** \paramend
- ** \blurb{This function sets the text font of all text menu items in the
- ** menu structure. The menu must be a box menu.}
- */
- {
- Ppoint pt;
- Pfloat charheight;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEBOXMENU)
- {
- menuptr->wsid = wsid;
- menuptr->font = font;
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "charheight"));
- poffset_elem_ptr(2);
- pdel_elem();
- pset_text_font(font);
- ptk_closestruct();
- if (menuptr->longstr[0] != '\0')
- {
- pt = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- ptk_computecharheight(menuptr->wsid, menuptr->longstr,
- &pt, menuptr->font, &charheight);
- if (charheight < menuptr->charheight)
- {
- menuptr->charheight = charheight;
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "charheight"));
- poffset_elem_ptr(1);
- pdel_elem();
- pset_char_ht(charheight);
- ptk_closestruct();
- }
- }
- }
- }
- } /* ptk_setboxmenutextfont */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setboxmenuattrs(C(Pint) wsid, C(Pint) menuid,
- C(Ptext_path) menupath, C(Pint) font, C(Pint) textcolour,
- C(Pint) intcolour, C(Pint) edgecolour, C(Pint) boxtlcolour,
- C(Pint) boxbrcolour, C(Pint) httextcolour,
- C(Pint) htintcolour, C(Pint) htedgecolour)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- PreANSI(Ptext_path menupath)
- PreANSI(Pint font)
- PreANSI(Pint textcolour)
- PreANSI(Pint intcolour)
- PreANSI(Pint edgecolour)
- PreANSI(Pint boxtlcolour)
- PreANSI(Pint boxbrcolour)
- PreANSI(Pint httextcolour)
- PreANSI(Pint htintcolour)
- PreANSI(Pint htedgecolour)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ptext\_path}{menupath}{path of box menu (left, right, up, down)}{IN}
- ** \param{Pint}{font}{text font}{IN}
- ** \param{Pint}{textcolour}{colour index for text}{IN}
- ** \param{Pint}{intcolour}{colour index for interior}{IN}
- ** \param{Pint}{edgecolour}{colour index for edges}{IN}
- ** \param{Pint}{boxtlcolour}{colour index for top-left of box}{IN}
- ** \param{Pint}{boxcolour}{colour index for bottom-right of box}{IN}
- ** \param{Pint}{httextcolour}{colour index for highlight text}{IN}
- ** \param{Pint}{htintcolour}{colour index for highlight interior}{IN}
- ** \param{Pint}{htedgecolour}{colour index for highlight edges}{IN}
- ** \paramend
- ** \blurb{This function sets the box menu path, text font and colour attribute
- ** values. The highlight colour indicies are used by the function
- ** {\tt ptk\_setboxmenuhighlightitem} to highlight a single menu item.}
- */
- {
- Ppoint pt;
- Pfloat charheight;
- Pint elptr, lstnum, intstate, err, itemnum;
- Pelem_type elemlist[3];
- Psearch_status srchstatus;
- ptkselcontent elcont;
- Pmatrix3 shiftmat;
- Ppoint3 tlpt;
- Pstore store;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEBOXMENU)
- {
- menuptr->wsid = wsid;
- menuptr->font = font;
- menuptr->menupath = menupath;
- menuptr->intcolour = intcolour;
- menuptr->edgecolour = edgecolour;
- menuptr->tlcolour = boxtlcolour;
- menuptr->brcolour = boxbrcolour;
- menuptr->textcolour = textcolour;
- menuptr->httlcolour = boxbrcolour;
- menuptr->htbrcolour = boxtlcolour;
- menuptr->htintcolour = htintcolour;
- menuptr->htedgecolour = htedgecolour;
- menuptr->httextcolour = httextcolour;
-
- /* set colours */
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "begin-menu"));
-
- /* replace all edges, text and interior (in special order) */
- elemlist[0] = PELEM_EDGE_COLR_IND;
- elemlist[1] = PELEM_TEXT_COLR_IND;
- elemlist[2] = PELEM_INT_COLR_IND;
- intstate = 1;
- do
- {
- ptk_findelemtype(elemlist, 3, PDIR_FORWARD, &srchstatus, &elptr, &lstnum);
- if (srchstatus == PSEARCH_STATUS_SUCCESS)
- {
- pset_elem_ptr(elptr);
- ptk_seteditmode(PEDIT_REPLACE);
- switch (lstnum)
- {
- case 0: /* PELEM_EDGE_COLR_IND */
- pset_edge_colr_ind(menuptr->edgecolour);
- break;
-
- case 1: /* PELEM_TEXT_COLR_IND */
- pset_text_colr_ind(menuptr->textcolour);
- break;
-
- case 2: /* PELEM_INT_COLR_IND */
- switch (intstate)
- {
- case 1: /* top-left edge */
- pset_int_colr_ind(menuptr->tlcolour);
- break;
-
- case 2: /* bottom-right edge */
- pset_int_colr_ind(menuptr->brcolour);
- break;
-
- case 3: /* box */
- pset_int_colr_ind(menuptr->intcolour);
- break;
- }
- intstate++;
- if (intstate == 4)
- intstate = 1;
- break;
- }
- ptk_unseteditmode();
- poffset_elem_ptr(1);
- }
- } while (srchstatus == PSEARCH_STATUS_SUCCESS);
-
- /* redo highlight item */
- if (menuptr->highlight > 0)
- {
- pset_elem_ptr(0);
- find_item(menuptr->menustid, menuptr->highlight, &elptr);
- pset_elem_ptr(elptr);
- redrawboxmenuitem(menuptr->httextcolour,
- menuptr->htintcolour, menuptr->htedgecolour,
- menuptr->httlcolour, menuptr->htbrcolour);
- }
- ptk_closestruct();
-
- /* set text font */
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "charheight"));
- poffset_elem_ptr(2);
- pdel_elem();
- pset_text_font(font);
- ptk_closestruct();
- if (menuptr->longstr[0] != '\0')
- {
- pt = ptk_point(menuptr->boxsize.x -
- (2.0 * menuptr->framesize.x),
- menuptr->boxsize.y -
- (2.0 * menuptr->framesize.y));
- ptk_computecharheight(menuptr->wsid, menuptr->longstr,
- &pt, menuptr->font, &charheight);
- if (charheight < menuptr->charheight)
- {
- menuptr->charheight = charheight;
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "charheight"));
- poffset_elem_ptr(1);
- pdel_elem();
- pset_char_ht(charheight);
- ptk_closestruct();
- }
- }
-
- /* set menu path */
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "begin-menu"));
-
- /* replace all local transformations following pick identifiers */
- elemlist[0] = PELEM_PICK_ID;
- elemlist[1] = PELEM_LOCAL_MODEL_TRAN3;
- do
- {
- ptk_findelemtype(elemlist, 2, PDIR_FORWARD, &srchstatus, &elptr, &lstnum);
- if (srchstatus == PSEARCH_STATUS_SUCCESS)
- {
- pset_elem_ptr(elptr);
- switch (lstnum)
- {
- case 0: /* PELEM_PICK_ID */
- pcreate_store(&err, &store);
- ptk_inqcurelemtypesizecontent(store, &err, &elcont);
- itemnum = elcont.eldata->int_data;
- ptk_delstore(store);
- break;
-
- case 1: /* PELEM_LOCAL_MODEL_TRAN3 */
- if (itemnum > 0)
- {
- tlpt = get_tlboxcorner(itemnum);
- ptk_shift3(&tlpt, PTYPE_REPLACE, shiftmat);
- ptk_seteditmode(PEDIT_REPLACE);
- pset_local_tran3(shiftmat, PTYPE_REPLACE);
- ptk_unseteditmode();
- itemnum = 0;
- }
- break;
- }
- poffset_elem_ptr(1);
- }
- } while (srchstatus == PSEARCH_STATUS_SUCCESS);
- ptk_closestruct();
- }
- }
- } /* ptk_setboxmenuattrs */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setboxmenuhighlightitem(C(Pint) menuid, C(Pint) itemnum)
- PreANSI(Pint menuid)
- PreANSI(Pint itemnum)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{itemnum}{menu item number}{IN}
- ** \paramend
- ** \blurb{This function highlights a menu item by setting the colour
- ** index values for the text, interior and edge of a box menu item.}
- */
- {
- Pint elptr;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEBOXMENU)
- {
- ptk_openstruct(menuptr->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(0);
- if (itemnum != menuptr->highlight)
- {
- /* redraw previously highlighted item in normal colours*/
- if (menuptr->highlight > 0)
- {
- /* redraw item */
- find_item(menuptr->menustid, menuptr->highlight, &elptr);
- pset_elem_ptr(elptr);
- redrawboxmenuitem(menuptr->textcolour,
- menuptr->intcolour, menuptr->edgecolour,
- menuptr->tlcolour, menuptr->brcolour);
- }
- /* redraw item in highlight colours */
- find_item(menuptr->menustid, itemnum, &elptr);
- pset_elem_ptr(elptr);
- redrawboxmenuitem(menuptr->httextcolour,
- menuptr->htintcolour, menuptr->htedgecolour,
- menuptr->httlcolour, menuptr->htbrcolour);
- }
- ptk_unseteditmode();
- ptk_closestruct();
- menuptr->highlight = itemnum;
- }
- }
- } /* ptk_setboxmenuhighlightitem */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_clearboxmenuhighlight(C(Pint) menuid)
- PreANSI(Pint menuid)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \paramend
- ** \blurb{This function returns the attributes of the highlighted menu item
- ** to their original values. If no item is highlighted the function is
- ** ignored.}
- */
- {
- Pint elptr;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->highlight > 0)
- {
- ptk_openstruct(menuptr->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(0);
-
- find_item(menuptr->menustid, menuptr->highlight, &elptr);
- pset_elem_ptr(elptr);
- redrawboxmenuitem(menuptr->textcolour,
- menuptr->intcolour, menuptr->edgecolour,
- menuptr->tlcolour, menuptr->brcolour);
-
- ptk_unseteditmode();
- ptk_closestruct();
- menuptr->highlight = 0;
- }
- }
- } /* ptk_clearboxmenuhighlight */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqpostedmenus(C(Pint) wsid, C(Pint) size,
- C(Pint_list *) menuids, C(Pint *) totalsize, C(Pint *) err)
- PreANSI(Pint wsid)
- PreANSI(Pint size)
- PreANSI(Pint_list *menuids)
- PreANSI(Pint *totalsize)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{size}{size of buffer}{IN}
- ** \param{Pint\_list *}{menuids}{list of posted menus}{OUT}
- ** \param{Pint *}{totalsize}{length of posted menus list}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to inquire the list of all menus
- ** which are posted to workstation {\tt wsid}. The error code is
- ** a standard PHIGS error code.}
- */
- {
- ptksmenu *ptrmenu;
- Pint numstructs, i;
- Pposted_struct_list structlist;
-
- *err = 0;
- *totalsize = 0;
- ptrmenu = firstmenu;
- while (ptrmenu != NULL)
- {
- if ((inintlst(wsid, &ptrmenu->posted) != -1))
- (*totalsize)++;
- ptrmenu = ptrmenu->next;
- }
- if (size >= *totalsize)
- {
- pinq_posted_structs(wsid, 0, 0, err, &structlist, &numstructs);
- structlist.postings = (Pposted_struct *)calloc(numstructs,
- sizeof(Pposted_struct));
- pinq_posted_structs(wsid, numstructs, 0, err, &structlist, &numstructs);
- menuids->num_ints = 0;
- for (i = 0; i < structlist.num_postings; i++)
- {
- if (ismenu(structlist.postings[i].id, &ptrmenu))
- {
- menuids->ints[menuids->num_ints] = ptrmenu->menuid;
- menuids->num_ints++;
- }
- }
- }
- } /* ptk_inqpostedmenus */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqmenuids(C(Pint) size, C(Pint_list *) menuids,
- C(Pint *) totalsize, C(Pint *) err)
- PreANSI(Pint size)
- PreANSI(Pint_list *menuids)
- PreANSI(Pint *totalsize)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{size}{size of buffer}{IN}
- ** \param{Pint\_list *}{menuids}{list of menus}{OUT}
- ** \param{Pint *}{totalsize}{length of menus list}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain a list of all menus
- ** in the PHIGS Toolkit menu store.}
- */
- {
- ptksmenu *ptrmenu;
-
- *err = 0;
- *totalsize = menucount;
- if (size >= *totalsize)
- {
- menuids->num_ints = 0;
- ptrmenu = firstmenu;
- while (ptrmenu != NULL)
- {
- menuids->ints[menuids->num_ints] = ptrmenu->menuid;
- menuids->num_ints++;
- ptrmenu = ptrmenu->next;
- }
- }
- } /* ptk_inqmenuids */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqmenustructid(C(Pint) menuid, C(Pint *) menustid,
- C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Pint *menustid)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint *}{menustid}{menu structure identifier}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the identifier
- ** of a menu structure. The error code = 1 if {\tt menuid} doesn't exist.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- *menustid = menuptr->menustid;
- else
- *err = 1;
- } /* ptk_inqmenustructid */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqmenuname(C(Pint) menuid, C(Pint *) name,
- C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Pint *name)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{windid}{menu identifier}{IN}
- ** \param{Pint *}{name}{menu name}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the menu name
- ** for use in the pick filter.
- ** The error code = 1 if {\tt menuid} doesn't exist.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- *name = menuptr->menuname;
- else
- *err = 1;
- } /* ptk_inqmenuname */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern ptkboolean ptk_inqfrontbackmenuid(C(Pint) wsid, C(Pint *) frontid,
- C(Pint *) backid, C(Pint *) err)
- PreANSI(Pint wsid)
- PreANSI(Pint *frontid)
- PreANSI(Pint *backid)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint *}{frontstid}{front menu identifier}{OUT}
- ** \param{Pint *}{backstid}{back menu identifier}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the menu identifiers
- ** of the front and back menus which are posted to workstation {\tt wsid}.
- ** These are the menus with the highest and lowest post priority.}
- **
- */
- {
- Pint ind;
-
- *err = 0;
- findwsid(wsid, &ind);
- if (wsmenus[ind].postedmenus)
- {
- *frontid = wsmenus[ind].frontptr->menuid;
- *backid = wsmenus[ind].backptr->menuid;
- return TRUE;
- }
- else
- return FALSE;
- } /* ptk_inqfrontbackmenuid */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqboxmenuattrs(C(Pint) menuid,
- C(Ptext_path *) menupath, C(Pint *) font, C(Pint *) textcolour,
- C(Pint *) intcolour, C(Pint *) edgecolour, C(Pint *) boxtlcolour,
- C(Pint *) boxbrcolour, C(Pint *) httextcolour,
- C(Pint *) htintcolour, C(Pint *) htedgecolour, C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Ptext_path *menupath)
- PreANSI(Pint *font)
- PreANSI(Pint *textcolour)
- PreANSI(Pint *intcolour)
- PreANSI(Pint *edgecolour)
- PreANSI(Pint *boxtlcolour)
- PreANSI(Pint *boxbrcolour)
- PreANSI(Pint *httextcolour)
- PreANSI(Pint *htintcolour)
- PreANSI(Pint *htedgecolour)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ptext\_path *}{menupath}{path of box menu (left, right, up, down)}{OUT}
- ** \param{Pint *}{font}{text font}{OUT}
- ** \param{Pint *}{textcolour}{colour index for text}{OUT}
- ** \param{Pint *}{intcolour}{colour index for interior}{OUT}
- ** \param{Pint *}{edgecolour}{colour index for edges}{OUT}
- ** \param{Pint *}{boxtlcolour}{colour index for top-left of box}{OUT}
- ** \param{Pint *}{boxcolour}{colour index for bottom-right of box}{OUT}
- ** \param{Pint *}{httextcolour}{colour index for highlight text}{OUT}
- ** \param{Pint *}{htintcolour}{colour index for highlight interior}{OUT}
- ** \param{Pint *}{htedgecolour}{colour index for highlight edges}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the boxmenu attribute
- ** values for {\tt menuid}. These include the menu path, text font and
- ** colour indicies. The error code = 1 if {\tt menuid} doesn't exist
- ** and = 2 if it is not a box menu.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEBOXMENU)
- {
- *menupath = menuptr->menupath;
- *font = menuptr->font;
- *textcolour = menuptr->textcolour;
- *intcolour = menuptr->intcolour;
- *edgecolour = menuptr->edgecolour;
- *boxtlcolour = menuptr->tlcolour;
- *boxbrcolour = menuptr->brcolour;
- *httextcolour = menuptr->httextcolour;
- *htintcolour = menuptr->htintcolour;
- *htedgecolour = menuptr->htedgecolour;
- }
- else
- *err = 2;
- }
- else
- *err = 1;
- } /* ptk_inqboxmenuattrs */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqmenuposition(C(Pint) menuid, C(Ppoint *) position,
- C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Ppoint *position)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Ppoint *}{position}{menu position}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the position of the
- ** top-left corner of first menu item. The position is returned in the
- ** range [0, 1]. The error code = 1 if {\tt menuid} doesn't exist.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- *position = menuptr->menuposition;
- else
- *err = 1;
- } /* ptk_inqmenuposition */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqboxmenuhighlightitem(C(Pint) menuid, C(Pint *) item,
- C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Pint *item)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint *}{item}{hightlight item number}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the item number of the
- ** currently highlight box menu item.
- ** The error code = 1 if {\tt menuid} doesn't exist and = 2 if there
- ** is no highlighted item.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->highlight > 0)
- *item = menuptr->highlight;
- else
- *err = 2;
- }
- else
- *err = 1;
- } /* ptk_inqboxmenuhighlightitem */
-
- /*--------------------------------------------------------------------------*/
- /*------------------- exported rotator routines ----------------------------*/
- /*--------------------------------------------------------------------------*/
-
- static void createrotator(C(Pint) wsid, C(Pint) menuid,
- C(ptkerotatortype) rottype, C(Ppoint *) size,
- C(char *) titlestr, C(Pfloat) titleheight, C(Pint) titlecolour,
- C(Pint) titlefont, C(Pint) arrowcolour, C(Pint) arrowedgecolour,
- C(Pint) intcolour, C(Pint) edgecolour, C(Pint) bannercolour,
- C(Pint) boxtlcolour, C(Pint) boxbrcolour)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- PreANSI(ptkerotatortype rottype)
- PreANSI(Ppoint *size)
- PreANSI(char *titlestr)
- PreANSI(Pfloat titleheight)
- PreANSI(Pint titlecolour)
- PreANSI(Pint titlefont)
- PreANSI(Pint arrowcolour)
- PreANSI(Pint arrowedgecolour)
- PreANSI(Pint intcolour)
- PreANSI(Pint edgecolour)
- PreANSI(Pint bannercolour)
- PreANSI(Pint boxtlcolour)
- PreANSI(Pint boxbrcolour)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{rotator identifier}{IN}
- ** \param{ptkerotatortype}{rottype}{rotator type}{IN}
- ** \param{Ppoint *}{size}{rotator size}{IN}
- ** \param{char *}{titlestr}{rotator title}{IN}
- ** \param{Pfloat}{titleheight}{rotator title height}{IN}
- ** \param{Pint}{titlecolour}{title colour index}{IN}
- ** \param{Pint}{titlefont}{title font}{IN}
- ** \param{Pint}{arrowcolour}{arrow interior colour index}{IN}
- ** \param{Pint}{arrowedgecolour}{arrow edge colour index}{IN}
- ** \param{Pint}{intcolour}{rotator interior colour index}{IN}
- ** \param{Pint}{edgecolour}{edge colour index}{IN}
- ** \param{Pint}{bannercolour}{banner colour index}{IN}
- ** \param{Pint}{boxtlcolour}{top-left colour index}{IN}
- ** \param{Pint}{boxbrcolour}{bottom-right colour index}{IN}
- ** \paramend
- ** \blurb{Create rotator with given specification.}
- */
- {
- Pmatrix3 matrix, mat, boxmat;
- char stname[30], str[10];
- Pint arrowid, menustid, elptr, pickval, err;
- Pfloat charheight;
- Plimit3 ubox, rbox;
- Ppoint3 arrowcentre, centre;
- Ppoint3 arrowshift, arrowscale, boxscale, boxpos;
- Ppoint_list sets;
- Ppoint pts[4], centresize, framesize, shift, scale, textpos;
- Ppoint boxsize, iconbox;
- Ptext_align txalign;
- Pint_list incl;
-
- setmenu(menuid);
- if (menuptr == NULL)
- {
- sprintf(stname, "ptk$menu%d", menuid);
- menustid = ptk_stringtoint("structureid", stname);
- ptk_createusermenu(menuid, menustid);
- setmenu(menuid);
- ptk_openstruct(menustid);
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "begin-menu"));
- poffset_elem_ptr(-2);
-
- /* rotator surrounds */
- menuptr->wsid = wsid;
- menuptr->font = titlefont;
- menuptr->menutype = PTKEROTATOR;
- menuptr->intcolour = intcolour;
- menuptr->edgecolour = edgecolour;
- menuptr->tlcolour = boxtlcolour;
- menuptr->brcolour = boxbrcolour;
- menuptr->textcolour = titlecolour;
- menuptr->arrowcolour = arrowcolour;
- menuptr->arrowedgecolour = arrowedgecolour;
- menuptr->bannercolour = bannercolour;
- menuptr->boxsize = *size;
- menuptr->boxsize.y += titleheight;
- menuptr->framesize = ptk_point(0.01, 0.01);
- strcpy(menuptr->longstr, titlestr);
-
- centre = ptk_point3(0.0, titleheight / 2.0, 0.0);
- centresize = *size;
- centresize.y += titleheight;
- centresize.x -= menuptr->framesize.x * 2.0;
- centresize.y -= menuptr->framesize.y * 2.0;
-
- ptk_framebox(¢re, ¢resize, &menuptr->framesize,
- intcolour, edgecolour, boxtlcolour, boxbrcolour);
- pts[0] = ptk_point(-centresize.x / 2.0, centresize.y / 2.0 -
- titleheight / 2.0);
- pts[1] = ptk_point(pts[0].x, pts[0].y + titleheight);
- pts[2] = ptk_point(pts[0].x + centresize.x, pts[1].y);
- pts[3] = ptk_point(pts[2].x, pts[0].y);
-
- poffset_elem_ptr(1); /* make title pickable */
- sets.num_points = 4;
- sets.points = pts;
- pset_int_colr_ind(bannercolour);
- ptk_fillareaset(1, &sets);
- /* Implementation dependent bit - because HP doesn't support
- ** INQUIRE TEXT EXTENT, kludge to size text in rotator banner.
- */
- #ifdef SUN
- menuptr->bannerbox = ptk_point(centresize.x, titleheight);
- #endif
- #ifdef HP
- menuptr->bannerbox = ptk_point(centresize.x, titleheight * 0.7);
- #endif
- #ifdef PEXSI
- menuptr->bannerbox = ptk_point(centresize.x, titleheight * 0.7);
- #endif
- txalign.hor = PHOR_CTR;
- txalign.vert = PVERT_BOTTOM;
- pset_text_align(&txalign);
- pset_text_font(menuptr->font);
- pset_text_colr_ind(titlecolour);
- plabel(ptk_stringtoint("label", "rotator$title"));
- ptk_computecharheight(wsid, titlestr, &menuptr->bannerbox, menuptr->font,
- &charheight);
- pset_char_ht(charheight);
- menuptr->bannercentre = ptk_point(centre.x, centresize.y / 2.0 -
- titleheight / 2.0);
- ptext(&menuptr->bannercentre, titlestr);
-
- /* arrows */
- pset_int_colr_ind(arrowcolour);
- pset_edge_colr_ind(arrowedgecolour);
-
- ptk_closestruct();
-
- arrowid = ptk_stringtoint("structureid", "ptk$arrow");
- /* create arrow structure which will be executed by 1d, 2d and 3d
- ** rotators.
- */
- if (!ptk_structexists(arrowid))
- {
- ptk_openstruct(arrowid);
- arrowcentre = ptk_point3(0.0, 0.0, 0.0);
- ptk_arrow(1.0, 1.0, &arrowcentre, 0.0);
- ptk_closestruct();
- }
-
- switch (rottype)
- {
-
- case PTKEONED:
- {
- Ppoint box1d, arrowsize, arrowspace;
-
- /* calculate 1d bounding box */
- box1d.x = box1d.y = PTKMIN(centresize.x, centresize.y);
-
- /* calculate arrow size and spacing */
- arrowsize.x = arrowsize.y = box1d.x / 3.0;
- arrowspace.x = arrowspace.y = arrowsize.x / 3.0;
-
- /* create arrow menu items */
- ptk_createstructmenuitem(menuid, arrowid, 1, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 2, PEDIT_INSERT, &err);
-
- /* put in transformations for arrows */
- boxscale = ptk_point3(arrowsize.x, arrowsize.y, 1.0);
- ptk_scale3(&boxscale, PTYPE_REPLACE, boxmat);
-
- ptk_openstruct(menustid);
- pset_elem_ptr(0);
- find_insertion_pt(menustid, 1, &elptr, &pickval);
- pset_elem_ptr(elptr);
- ptk_unitmatrix3(mat);
-
- /* up arrow */
- arrowshift = ptk_point3(0.0,
- arrowspace.y + (arrowsize.y / 2.0), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- /* down arrow */
- arrowshift = ptk_point3(0.0,
- -(arrowspace.y + (arrowsize.y / 2.0)), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- arrowscale = ptk_point3(1.0, -1.0, 1.0);
- ptk_scale3(&arrowscale, PTYPE_PRECONCAT, mat);
- /* jump to just before next execute element */
- poffset_elem_ptr(2);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- ptk_closestruct();
- }
- break;
-
- case PTKETWOD:
- {
- Ppoint box2d, arrowsize, arrowspace;
-
- /* calculate 2d bounding box */
- box2d.x = box2d.y = PTKMIN(centresize.x, centresize.y);
-
- /* calculate arrow size and spacing */
- arrowsize.x = arrowsize.y = box2d.x / 3.0;
- arrowspace.x = arrowspace.y = arrowsize.x / 3.0;
-
- /* create arrow menu items */
- ptk_createstructmenuitem(menuid, arrowid, 1, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 2, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 3, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 4, PEDIT_INSERT, &err);
-
- /* put in transformations for arrows */
- boxscale = ptk_point3(arrowsize.x, arrowsize.y, 1.0);
- ptk_scale3(&boxscale, PTYPE_REPLACE, boxmat);
-
- ptk_openstruct(menustid);
- pset_elem_ptr(0);
- find_insertion_pt(menustid, 1, &elptr, &pickval);
- pset_elem_ptr(elptr);
- ptk_unitmatrix3(mat);
- arrowshift = ptk_point3(0.0,
- arrowspace.y + (arrowsize.y / 2.0), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- /* m is a shift by (0.0, arrowsep) */
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- arrowshift = ptk_point3(0.0,
- -(arrowspace.y + (arrowsize.y / 2.0)), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- arrowscale = ptk_point3(1.0, -1.0, 1.0);
- ptk_scale3(&arrowscale, PTYPE_PRECONCAT, mat);
- /* jump to just before next execute element */
- poffset_elem_ptr(2);
- /* m is now a reflection in the x axis. */
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- poffset_elem_ptr(2);
- /* add shift component to matrix to shift by (0, arrowsep, 0) */
-
- arrowshift = ptk_point3(0.0,
- (arrowspace.x + (arrowsize.x / 2.0)), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_rotate3(90.0, PTKEZAXIS, PTYPE_POSTCONCAT, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- /* +x is a reflection of -x in the y axis */
- arrowscale = ptk_point3(-1.0, 1.0, 1.0);
- ptk_scale3(&arrowscale, PTYPE_POSTCONCAT, mat);
- poffset_elem_ptr(2);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- ptk_closestruct();
- }
- break;
-
- case PTKETHREED:
- {
- Ppoint box3d, arrowsize, arrowspace;
- Pfloat aspectratio, aspectratio3d, diff;
-
- /* calculate 3d bounding box */
- box3d = centresize;
- /* calculate aspect ratio of box */
- aspectratio = centresize.y / centresize.x;
- aspectratio3d = 2.0 / 3.0;
- if (aspectratio < aspectratio3d)
- {
- /* decrease x */
- diff = (centresize.x - ((1.0 / aspectratio3d) * centresize.y));
- box3d.x -= diff;
- }
- else
- if (aspectratio > aspectratio3d)
- {
- /* decrease y */
- diff = (centresize.y - (aspectratio3d * centresize.x));
- box3d.y -= diff;
- }
-
- /* calculate arrow size and spacing */
- arrowsize.x = arrowsize.y = (box3d.x / 17.0) * 3.0;
- arrowspace = ptk_point(arrowsize.x / 3.0, arrowsize.y / 3.0);
-
- /* create arrow menu items */
- ptk_createstructmenuitem(menuid, arrowid, 1, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 2, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 3, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 4, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 5, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(menuid, arrowid, 6, PEDIT_INSERT, &err);
-
- /* put in transformations for arrows */
- boxscale = ptk_point3(arrowsize.x, arrowsize.y, 1.0);
- ptk_scale3(&boxscale, PTYPE_REPLACE, boxmat);
-
- ptk_openstruct(menustid);
- pset_elem_ptr(0);
- find_insertion_pt(menustid, 1, &elptr, &pickval);
- pset_elem_ptr(elptr);
- ptk_unitmatrix3(mat);
-
- arrowshift = ptk_point3(0.0,
- arrowspace.y + (arrowsize.y / 2.0), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- arrowshift = ptk_point3(0.0,
- -(arrowspace.y + (arrowsize.y / 2.0)), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- arrowscale = ptk_point3(1.0, -1.0, 1.0);
- ptk_scale3(&arrowscale, PTYPE_PRECONCAT, mat);
- /* jump to just before next execute element */
- poffset_elem_ptr(2);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- poffset_elem_ptr(2);
- arrowshift = ptk_point3(0.0,
- (arrowspace.y + (arrowsize.y / 2.0)), 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_rotate3(90.0, PTKEZAXIS, PTYPE_POSTCONCAT, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- arrowscale = ptk_point3(-1.0, 1.0, 1.0);
- ptk_scale3(&arrowscale, PTYPE_POSTCONCAT, mat);
- poffset_elem_ptr(2);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- poffset_elem_ptr(2);
- arrowshift = ptk_point3((arrowspace.y * 3.0) / 2.0 + arrowsize.y +
- (arrowsize.x / 2.0), 0.0, 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
-
- poffset_elem_ptr(2);
- arrowshift = ptk_point3(-((arrowspace.y * 3.0) / 2.0 + arrowsize.y +
- (arrowsize.x / 2.0)), 0.0, 0.0);
- ptk_shift3(&arrowshift, PTYPE_REPLACE, mat);
- ptk_concatenatematrix3(PTYPE_PRECONCAT, boxmat, mat, mat);
- pset_local_tran3(mat, PTYPE_REPLACE);
- ptk_closestruct();
- }
- break;
- }
- ptk_unseteditmode();
- }
- } /* createrotator */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_createrotator(C(Pint) wsid, C(Pint) menuid,
- C(ptkerotatortype) rottype, C(Ppoint *) size,
- C(char *) titlestr, C(Pfloat) titleheight)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- PreANSI(ptkerotatortype rottype)
- PreANSI(Ppoint *size)
- PreANSI(char *titlestr)
- PreANSI(Pfloat titleheight)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{rotator identifier}{IN}
- ** \param{ptkerotatortype}{rottype}{rotator type}{IN}
- ** \param{Ppoint *}{size}{rotator size}{IN}
- ** \param{char *}{titlestr}{rotator title}{IN}
- ** \param{Pfloat}{titleheight}{rotator title height}{IN}
- ** \paramend
- ** \blurb{This function creates a special form of user menu called a
- ** rotator. Rotators consist of an arrangement of arrows and are useful
- ** for defining rotation values and direction in a user interface.
- ** There are three types of rotator available: 1D, 2D and 3D, and each
- ** having an increasing number of arrows.
- ** This function requires hashtables "structureid", "label", "name".}
- */
- {
- createrotator(wsid, menuid, rottype, size, titlestr, titleheight,
- 0, 1, 0, 1, 0, 0, 1, 1, 1);
- } /* ptk_createrotator */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setrotatortitle(C(Pint) menuid, C(char *) titlestr)
- PreANSI(Pint menuid)
- PreANSI(char *titlestr)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{char *}{titlestr}{title string of rotator banner}{IN}
- ** \paramend
- ** \blurb{This function sets the title string of the rotator menu
- ** to be {\tt titlestr}. The string is automatically scaled to fit
- ** in the rotator title box.}
- */
- {
- Pfloat charheight;
- Pint totlen;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype = PTKEROTATOR)
- {
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "rotator$title"));
- poffset_elem_ptr(1);
- ptk_seteditmode(PEDIT_REPLACE);
- ptk_computecharheight(menuptr->wsid, titlestr, &menuptr->bannerbox,
- menuptr->font, &charheight);
- pset_char_ht(charheight);
- poffset_elem_ptr(1);
- ptext(&menuptr->bannercentre, titlestr);
- ptk_unseteditmode();
- ptk_closestruct();
- totlen = strlen(titlestr) + 1;
- strncpy(menuptr->longstr, titlestr, totlen);
- }
- }
- } /* ptk_setrotatortitle */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_setrotatorattrs(C(Pint) wsid, C(Pint) menuid,
- C(Pint) titlefont, C(Pint) titlecolour,
- C(Pint) arrowcolour, C(Pint) arrowedgecolour,
- C(Pint) intcolour, C(Pint) edgecolour, C(Pint) bannercolour,
- C(Pint) boxtlcolour, C(Pint) boxbrcolour)
- PreANSI(Pint wsid)
- PreANSI(Pint menuid)
- PreANSI(Pint titlefont)
- PreANSI(Pint titlecolour)
- PreANSI(Pint arrowcolour)
- PreANSI(Pint arrowedgecolour)
- PreANSI(Pint intcolour)
- PreANSI(Pint edgecolour)
- PreANSI(Pint bannercolour)
- PreANSI(Pint boxtlcolour)
- PreANSI(Pint boxbrcolour)
- /*
- ** \parambegin
- ** \param{Pint}{wsid}{workstation identifier}{IN}
- ** \param{Pint}{menuid}{rotator identifier}{IN}
- ** \param{Pint}{titlefont}{title font}{IN}
- ** \param{Pint}{titlecolour}{title colour index}{IN}
- ** \param{Pint}{arrowcolour}{arrow interior colour index}{IN}
- ** \param{Pint}{arrowedgecolour}{arrow edge colour index}{IN}
- ** \param{Pint}{intcolour}{rotator interior colour index}{IN}
- ** \param{Pint}{edgecolour}{edge colour index}{IN}
- ** \param{Pint}{bannercolour}{banner colour index}{IN}
- ** \param{Pint}{boxtlcolour}{top-left colour index}{IN}
- ** \param{Pint}{boxbrcolour}{bottom-right colour index}{IN}
- ** \paramend
- ** \blurb{This function sets the attribute values of a rotator menu.
- ** The arrows are drawn within a box similar to that of box menu
- ** items and the box has an area for a title string. All arrows
- ** are drawn with the same colour values defined by {\tt arrowcolour}
- ** for the interior and {\tt arrowedgecolour} for the outline.}
- */
- {
- Pfloat charheight;
- Pint elptr, lstnum, intstate, edgestate;
- Pelem_type elemlist[3];
- Psearch_status srchstatus;
-
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEROTATOR)
- {
- menuptr->wsid = wsid;
- menuptr->font = titlefont;
- menuptr->intcolour = intcolour;
- menuptr->edgecolour = edgecolour;
- menuptr->tlcolour = boxtlcolour;
- menuptr->brcolour = boxbrcolour;
- menuptr->textcolour = titlecolour;
- menuptr->arrowcolour = arrowcolour;
- menuptr->arrowedgecolour = arrowedgecolour;
- menuptr->bannercolour = bannercolour;
-
- /* set colours */
- ptk_openstruct(menuptr->menustid);
- pset_elem_ptr(0);
-
- /* replace all edges, text and interior (in special order) */
- elemlist[0] = PELEM_EDGE_COLR_IND;
- elemlist[1] = PELEM_TEXT_COLR_IND;
- elemlist[2] = PELEM_INT_COLR_IND;
- intstate = edgestate = 1;
- do
- {
- ptk_findelemtype(elemlist, 3, PDIR_FORWARD, &srchstatus, &elptr, &lstnum);
- if (srchstatus == PSEARCH_STATUS_SUCCESS)
- {
- pset_elem_ptr(elptr);
- ptk_seteditmode(PEDIT_REPLACE);
- switch (lstnum)
- {
- case 0: /* PELEM_EDGE_COLR_IND */
- if (edgestate == 1)
- pset_edge_colr_ind(edgecolour);
- else
- pset_edge_colr_ind(arrowedgecolour);
- edgestate++;
- break;
-
- case 1: /* PELEM_TEXT_COLR_IND */
- pset_text_colr_ind(titlecolour);
- break;
-
- case 2: /* PELEM_INT_COLR_IND */
- switch (intstate)
- {
- case 1: /* top-left edge */
- pset_int_colr_ind(boxtlcolour);
- break;
-
- case 2: /* bottom-right edge */
- pset_int_colr_ind(boxbrcolour);
- break;
-
- case 3: /* box */
- pset_int_colr_ind(intcolour);
- break;
-
- case 4: /* banner */
- pset_int_colr_ind(bannercolour);
- break;
-
- case 5: /* arrow */
- pset_int_colr_ind(arrowcolour);
- break;
- }
- intstate++;
- break;
- }
- ptk_unseteditmode();
- poffset_elem_ptr(1);
- }
- } while (srchstatus == PSEARCH_STATUS_SUCCESS);
- ptk_closestruct();
-
- /* set font */
- ptk_openstruct(menuptr->menustid);
- ptk_seteditmode(PEDIT_INSERT);
- pset_elem_ptr(0);
- pset_elem_ptr_label(ptk_stringtoint("label", "rotator$title"));
- poffset_elem_ptr(-2);
- pdel_elem();
- pset_text_font(titlefont);
-
- if (menuptr->longstr[0] != '\0')
- {
- ptk_computecharheight(wsid, menuptr->longstr,
- &menuptr->bannerbox, titlefont, &charheight);
- poffset_elem_ptr(3);
- pdel_elem();
- pset_char_ht(charheight);
- }
- ptk_unseteditmode();
- ptk_closestruct();
- }
- }
- } /* ptk_setrotatorattrs */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqrotatortitle(C(Pint) menuid, C(Pint) len,
- C(char *) titlestr, C(Pint *) totlen, C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Pint len)
- PreANSI(char *titlestr)
- PreANSI(Pint *totlen)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{menu identifier}{IN}
- ** \param{Pint}{len}{length of string}{IN}
- ** \param{char *}{titlestr}{title string of rotator banner}{IN}
- ** \param{Pint *}{totlen}{actual length of string}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the title string of a rotator
- ** menu. The error code = 1 if {\tt menuid} doesn't exist and = 2 if
- ** the menu is not a rotator.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEROTATOR)
- {
- *totlen = strlen(menuptr->longstr) + 1;
- if (len >= *totlen)
- strncpy(titlestr, menuptr->longstr, *totlen);
- }
- else
- *err = 2;
- }
- else
- *err = 1;
- } /* ptk_inqrotatortitle */
-
- /*--------------------------------------------------------------------------*/
-
- /*function:external*/
- extern void ptk_inqrotatorattrs(C(Pint) menuid,
- C(Pint *) titlefont, C(Pint *) titlecolour,
- C(Pint *) arrowcolour, C(Pint *) arrowedgecolour,
- C(Pint *) intcolour, C(Pint *) edgecolour, C(Pint *) bannercolour,
- C(Pint *) boxtlcolour, C(Pint *) boxbrcolour, C(Pint *) err)
- PreANSI(Pint menuid)
- PreANSI(Pint *titlefont)
- PreANSI(Pint *titlecolour)
- PreANSI(Pint *arrowcolour)
- PreANSI(Pint *arrowedgecolour)
- PreANSI(Pint *intcolour)
- PreANSI(Pint *edgecolour)
- PreANSI(Pint *bannercolour)
- PreANSI(Pint *boxtlcolour)
- PreANSI(Pint *boxbrcolour)
- PreANSI(Pint *err)
- /*
- ** \parambegin
- ** \param{Pint}{menuid}{rotator identifier}{IN}
- ** \param{Pint *}{titlefont}{title font}{OUT}
- ** \param{Pint *}{titlecolour}{title colour index}{OUT}
- ** \param{Pint *}{arrowcolour}{arrow interior colour index}{OUT}
- ** \param{Pint *}{arrowedgecolour}{arrow edge colour index}{OUT}
- ** \param{Pint *}{intcolour}{rotator interior colour index}{OUT}
- ** \param{Pint *}{edgecolour}{edge colour index}{OUT}
- ** \param{Pint *}{bannercolour}{banner colour index}{OUT}
- ** \param{Pint *}{boxtlcolour}{top-left colour index}{OUT}
- ** \param{Pint *}{boxbrcolour}{bottom-right colour index}{OUT}
- ** \param{Pint *}{err}{error indicator}{OUT}
- ** \paramend
- ** \blurb{This function may be used to obtain the attribute values of
- ** a rotator menu. The error code = 1 if {\tt menuid} doesn't exist and = 2 if
- ** the menu is not a rotator.}
- */
- {
- *err = 0;
- setmenu(menuid);
- if (menuptr != NULL)
- {
- if (menuptr->menutype == PTKEROTATOR)
- {
- *titlefont = menuptr->font;
- *titlecolour = menuptr->textcolour;
- *intcolour = menuptr->intcolour;
- *edgecolour = menuptr->edgecolour;
- *boxtlcolour = menuptr->tlcolour;
- *boxbrcolour = menuptr->brcolour;
- *arrowcolour = menuptr->arrowcolour;
- *arrowedgecolour = menuptr->arrowedgecolour;
- *bannercolour = menuptr->bannercolour;
- }
- else
- *err = 2;
- }
- else
- *err = 1;
- } /* ptk_inqrotatorattrs */
-
- /*--------------------------------------------------------------------------*/
-
- /* end of menu.c */
-